Pergunta

I recently wanted to store and retrieve NSArrays from user defaults, and I found and used the suggestion at Storing custom objects in an NSMutableArray in NSUserDefaults, which works fine.

In retrospect, however, it would seem this is overkill if you are using standard collection classes, not custom objects. Can anyone confirm that the main benefit of the proposed solution I am using (linked above) is that you can store custom classes in this way, but that for working with NSArray where the contents are strings or other arrays or standard dictionaries, this approach with the NSKeyedArchiver is unnecessary?

Foi útil?

Solução

Yes, see the NSUserDefaults documentation at:

setObject:forKey:

The value parameter can be only property list objects: NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. For NSArray and NSDictionary objects, their contents must be property list objects.

You only need to use an NSCoder like NSKeyedArchiver if you need to covert your object to NSData.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top