Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 :)