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

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?

Thanks

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?

Thanks

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