I'm wondering why there is a -arrayForKey: method, but no -setArrayForKey: method. How could I set that array?
+2
A:
- (void)setObject:(id)value forKey:(NSString *)defaultName
This allows one to set any typical plist object, including an NSArray.
arrayForKey appears to just be a convenience method.
Nick Veys
2009-08-27 17:05:29
+2
A:
Just use setObject:forKey:
. I guess the reason that there's a special arrayForKey:
and dictionaryForKey:
etc. is that you get better type safety and don't have to cast. If you use these methods and the element in the defaults does not match the type, then nil
is returned.
Rüdiger Hanke
2009-08-27 17:07:04
Note that the -arrayForKey: etc. methods do give you one extra feature. If the object in the defaults of an unexpected type (e.g. a string, perhaps entered directly by the user), it will be ignored, and nil returned.
Mike Abdullah
2009-08-29 08:52:34
That's what the last sentence was supposed to mean :).
Rüdiger Hanke
2009-08-29 10:06:56
+1
A:
arrayForKey
and dictionaryForKey
are getters. Use setObject
to set an array.
thomax
2010-04-07 21:00:35