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!

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


Adding names then displaying in label

I am making an iOS app in which I need the user to be able to add a multiple names. These names will then be stored and displayed 1 at a time in a label. When the device is shaked the label will then display the next name in the list. I have looked into Core Data and NSArrays but i don't know the best way of doing this?


5 Answers

Hey Tom,

If you only need those names to be stored for a short period of time (the app's execution time, for instance) use NSArray-s, if you want the data to persist, even if you close the app, then you should save it with Core Data, or, more simple, with NSUserDefaults.

Hope it helped you somehow :)

Thanks for the help.

Can the names be put in by the user using a text field and then edited at a later date?


Not sure if I understand correctly you question, but I think you want to create the names during the app's execution, right? Yes, it's possible. Make sure you use NSMutableArray for that.

If I store the list in an array will the list be deleted if the app is in the background whilst multitasking?

Yes, it should be in memory and available for using the data inside it, even if the app goes into background (if using multitasking).