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 Swift Collections and Control Flow Introduction to Collections Adding Items to Arrays

Gabriel Lopez
Gabriel Lopez
354 Points

EXC_BAD_ACCESS error when coding an array

When trying to code an array such as var todo: [String] = "Finish collections course" , "Buy groceries"]

I run into this error message:

Playground execution failed:

error: Execution was interrupted, reason : EXC_BAD_ACCESS ( code =1, address = 0x0). The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

I am running Xcode 11.1 and I have tried restarting Xcode, trying it in a new page, and creating a new file.

2 Answers

Michael Hulet
MOD
Michael Hulet
Treehouse Moderator 47,822 Points

Playgrounds can be weird with it's error messages sometimes, but I'm surprised this compiled (unless this is just Playgrounds crashing instead of your code). You're missing an opening square bracket ([) at the beginning of your array definition, so that code won't compile. Swift will also understand that you're creating an array of Strings from the value you give the variable, so you also don't strictly need to explicitly declare the variable's type, though it will still work if you do

Gabriel Lopez
Gabriel Lopez
354 Points

I made a mistake in copying down my code, I originally had the opening square bracket ([). It gives me that error when trying to make any list or dictionary like the example below.

["LGA": "La Guardia"]