Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa - Store an NSString value

I want to store an NSString variable, that I receive from a JSON request, for future use. So when the user loads the app again, it loads that value (an NSString) that I stored.

What is the best way to store that kind of information?

like image 298
88fsantos Avatar asked Feb 19 '23 22:02

88fsantos


1 Answers

NSUserDefaults is what you're looking for.

Save string:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:theStringToSave forKey:@"keyToLookupString"];
[prefs synchronize];

Retrieve string:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *theSavedString = [prefs stringForKey:@"keyToLookupString"];
like image 137
Anne Avatar answered Mar 04 '23 03:03

Anne