Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift Collections and Control Flow Introduction to Collections Working With Arrays

Hugo Moutinho
Hugo Moutinho
1,253 Points

Can't seem to append on one array, but working fine with another one

I tried this exercise Array, which is:

var todo: [String] = ["Finish collections course","Buy groceries","Respond to emails"]

I use the method .append and it works just fine. However, when I try to use the same method on the following function, I get an error

var secondTaskList: [String] = ["Mow the lawn"] secondTaskList.append("Pay bills") secondTaskList.append("Pay bills") -----> Same error with unary addition as well

I have no idea why it works fine on one case and it doesn't on the other one.

Any light?

P.S.: I thought it was something about using uppercase, but then there was an exercise in this module which used it it. Now I'm just more confused =D

3 Answers

Jeff McDivitt
Jeff McDivitt
23,970 Points

This works fine? Where are you running into an issue?

Hugo Moutinho
Hugo Moutinho
1,253 Points

Well, that's weird. It's working fine now, but I haven't change anything (Xcode crazy?)

Anyway, what was happening was that I couldn't .append anything into the 'seconTaskList', even though I was declaring it as a VAR instead of LET. When you replied, I tested it again and then it worked just fine.

Thanks for your time and sorry for the trouble though

Jeff McDivitt
Jeff McDivitt
23,970 Points

Is this what you are doing?

var todo: [String] = ["Finish collections course","Buy groceries","Respond to emails"]

todo.append("PayBills")

var secondTaskList: [String] = ["Mow the lawn"]

secondTaskList.append("PayBills")
Hugo Moutinho
Hugo Moutinho
1,253 Points

Yep. Pretty much like that.

Jeff McDivitt
Jeff McDivitt
23,970 Points

No Worries - I don't mind assisting at all. Happy Coding!