Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the easiest way to persist data in an iPhone app?

I want to persist a very simple string. For example "abc". What's the easiest way to do this? I don't want to use a SqlLite database.

like image 776
MrDatabase Avatar asked Nov 13 '09 19:11

MrDatabase


People also ask

What technologies are used to persist data iOS?

iOS includes a storage technology called Archives that few iOS developers know. Archives allow you to encode data with complex relationship graphs into a binary form throug the use of coders and decoders. You can then store this data in files or send it over a network.

How does iPhone store app data?

Access third-party app data on all your devices When you set up iCloud for a third-party app, your app data is stored in iCloud instead of locally on your device. Because your data is stored in the cloud, it stays up to date anywhere you've set up iCloud for the app, including your iPhone, iPad, iPod touch, and Mac.

Where do iOS apps store data?

In iOS, typically, apps store their data in a folder named Documents , that is saved in a location next to where the app itself is installed (†). It is important to note that you do not need a jailbroken phone to access this folder.


1 Answers

If it is just one single string NSUserDefaults is probably the easiest way.

// write
[[NSUserDefaults standardUserDefaults] setObject:@"abc" forKey:@"MY_PERSISTENT_KEY"];

// read
NSString *abc = [[NSUserDefaults standardUserDefaults] valueForKey:@"MY_PERSISTENT_KEY"];
like image 184
Markus Müller-Simhofer Avatar answered Sep 24 '22 15:09

Markus Müller-Simhofer