I'm making an iOS app in Xcode 4 that needs to save one NSString variable. Does anyone know if using a .plist file is the best way to do this if so, what code do you need to store and retrive NSStrings?
Any help would be awesome!
I'm making an iOS app in Xcode 4 that needs to save one NSString variable. Does anyone know if using a .plist file is the best way to do this if so, what code do you need to store and retrive NSStrings?
Any help would be awesome!
Best place would be to store it in NSUserDefaults:
[[NSUserDefaults standardUserDefaults] setObject:@"My String" forKey:@"kMyStringKey"];
Then to call it:
lblMyLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"kMyStringKey"];
there are multiple ways to store an NSString because needs vary. Plist in this case is more than necessary (based on the description).
Option A You could just use: - [NSString writeToURL:atomically:encoding:error:]. in this case, you only need to remember the file URL and encoding you saved it in.
Option B another option would be to save it via NSCoding -- this allows NSString to choose the serialized representation it finds is best, given the string it represents.