views:

27

answers:

1

I have an object. It has only two NSStrings as properties.

I created an array to hold several of these objects.

Do I need to use NSKeyedArchiver to save this array to disk, or can I just use NSUserDefaults?

A: 

You can just use [[NSUserDefaults standardUserDefaults] setObject:myArray forKey:myKey]; for writing and [[NSUserDefaults standardUserDefaults] arrayForKey:myKey]; for reading (there is no setArray:forKey: as it's not needed).

Also, if you got an array that you don't want to store inside NSUserDefaults there's an easy possibility to write and read arrays: -[NSArray writeToFile:atomically:] and +[NSArray arrayWithContentsOfFile:]. There also the same methods for NSDictionary to easily read/write dictionaries. Of course you're always free to use NSKeyed(Un)Archiver as well.

DarkDust
If I try to do that I get an "attempt to insert non-property value" error.
awakeFromNib
@awakeFromNib: What did you do ? I just verified with this code: `NSArray *array = [NSArray arrayWithObjects:@"One", @"Two", nil]; [[NSUserDefaults standardUserDefaults] setObject:array forKey:@"TestKey"];` which works exactly as expected.
DarkDust