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

Egor Bedunkevich
Egor Bedunkevich
643 Points

Creating Arrays

I did some code and I do understand what we have learned about arrays, but I came across something that I had to ask. Let us say that I am creating an array outside any other methods(not sure about what they are called. Can some one explain?):

var notUsableArray = ["Hello", "World", "Swift", "Programming"]

override func viewDidLoad() { super.viewDidLoad()

}

I have created my array. I know that I can add more items into it, but why canΒ΄t I do this?

var notUsableArray = ["Hello", "World", "Swift", "Programming"]

notUsableArray += ["Hello", "Stuff", "Code"]

override func viewDidLoad() { super.viewDidLoad()

}

I can do in viewDidLoad and more, but why canΒ΄t I do it there? The error that I get is : Expected decleration

Please explain this to me in detail :)