2

I am looking forward to save around 10 strings in my iPhone App. I want the users to be able to edit this strings and when they open the app next time they should be able to see the edited values again.

I wanted to know

  1. what are the possible ways in which this can be achieved? (SQLite, Text file, etc)
  2. Which option would suit my requirements best (in terms of trade-offs between complexity & performance
  3. Any sample code or links pointing to the relevant sample code / tutorial

Thanks in advance.

EDIT 1:

I was thinking how would it be if I initially store the strings inside an NSMutableArray and then persist it for storage and read it again when the app opens the next time? Is this worth doing for my requirements?

Mahendra Liya
  • 12,912
  • 14
  • 88
  • 114

3 Answers3

2

1) database (SQLLite), flat-file (plist) or nsuserdefaults

2) nsuserdefaults (if you don't need any security)

3)

save to nsuserdefaults:

[[NSUserDefaults standardUserDefaults] setObject:stringone forKey:@"string1"];
[[NSUserDefaults standardUserDefaults] synchronize];

retrieve from nsuserdefaults:

NSString *stringone = [[NSUserDefaults standardUserDefaults] objectForKey:@"string1"];
ader
  • 5,403
  • 1
  • 21
  • 26
2

I would use NSUserDefaults, if you only have to save 10 strings. it's the fastest way.

You can get an example here: http://www.cocoadev.com/index.pl?NSUserDefaults

Hope this helps

oriolpons
  • 1,883
  • 12
  • 20
2

there are several options like
1.NSUserDefaults - (Example)
2.SQLite - (Example)
3.Core data - (Example)
4.plist
5.text file - (S.O. Ans)

NSUserDefaults is for user preferences, usually basic objects like NSString or NSNumber. If I am looking forward to save around 10 strings in my iPhone App, I will definitely go with NSUserDefaults

Community
  • 1
  • 1
Ankur
  • 5,086
  • 19
  • 37
  • 62
  • Hi, thank you for all the suggestions. I decided to go with a `.plist` file. What I am doing is reading the contents of the `.plist` into a `NSArray`, if the contents are `nil`, then I initialize the `NSArray` object with default strings. – Mahendra Liya Jan 11 '12 at 11:04
  • Any suggestions / sample code for saving the `NSArray` containing the edited strings back to the sample `.plist` file? I have the `.plist' file in `Documents`.Thanks in advance. – Mahendra Liya Jan 11 '12 at 11:05
  • 1
    hope this helps .... 1) http://stackoverflow.com/questions/6070568/ios-store-two-nsmutablearray-in-a-plist-file 2) http://forums.macrumors.com/archive/index.php/t-1146181.html – Ankur Jan 11 '12 at 11:11