Save string to the NSUserDefaults?

Shishir.bobby picture Shishir.bobby · Jun 19, 2010 · Viewed 173.6k times · Source

How to save a string into the NSUserDefaults?

Answer

drawnonward picture drawnonward · Jun 19, 2010
NSString *valueToSave = @"someValue";
[[NSUserDefaults standardUserDefaults] setObject:valueToSave forKey:@"preferenceName"];
[[NSUserDefaults standardUserDefaults] synchronize];

to get it back later

NSString *savedValue = [[NSUserDefaults standardUserDefaults]
    stringForKey:@"preferenceName"];