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

General IOS Question

I have a question about storing memory in iPhone. If you take in a very small amount of user info that you want to be stored so that it can be seen the next time the app is opened after it is terminated, do you still have to somehow store that user information on the phone even though it is very small. And if you do, how would you go about accomplishing this? Thank you in advance!

5 Answers

You will need to store that data on the phone or somewhere and make a connection to it for instance on a web server that your app connects to.

As to how to do this I am unsure I am going through the track as we speak but I remember seeing in the library a thing called.... Core Data and that is essentially what you are looking for.

Another way to do this is to read and write files example: store the user data in a .txt or .dat file and load that data when needed. I still suggest you take a look at Core Data

For small amount of data you could use NSUserDefaults.

example

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];

  NSDictionary * data = @{@"users":@[@"U1", @"U2"],
                          @"phones":@[@2239, @22331]
                          };

  [defaults setObject:data forKey:@"User Data"];

  [defaults synchronize];

I have three NSMutableArrays that will need to be saved so how would I save that. Also, where would I implement this code to save the data and how would I access the data after the app terminates?

Okay, thank you!