How to install NSArray in NSUserDefaults?

I am wondering why the -arrayForKey: method method exists, but no -setArrayForKey: method. How can I set this array?

+3
source share
3 answers

Just use it setObject:forKey:. I think the reason is that special arrayForKey:and dictionaryForKey:etc. - this is what you get the best type security and should not give up. If you use these methods, and the element is not the default type, it is returned nil.

+21
source

arrayForKeyand dictionaryForKeyare getters. Use setObjectto set the array.

+5
source

- (void)setObject:(id)value forKey:(NSString *)defaultName

plist, NSArray.

arrayForKey is apparently just a convenience method.

+2
source

All Articles