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.
+13
A:
If it is just one single string NSUserDefaults is probably the easiest way.
// write
[[NSUserDefaults standardDefaults] setObject:@"abc" forKey:@"MY_PERSISTENT_KEY"];
// read
NSString *abc = [[NSUserDefaults standardDefaults] valueForKey:@"MY_PERSISTENT_KEY"];
Markus Müller
2009-11-13 20:05:18
A:
You can make your objects conform to NSCoding, then write them to a file using an NSKeyedArchiver.
NSString* path = [self pathForDataFile];
NSMutableDictionary* rootObject = [NSMutableDictionary dictionary];
[rootObject setValue: someObject forKey: @"SomeObject"];
// Commit data to file
[NSKeyedArchiver archiveRootObject: rootObject toFile: path];
jessecurry
2009-11-13 22:07:49