2

Possible Duplicate:
Where's the difference between setObject:forKey: and setValue:forKey: in NSMutableDictionary?

Hi,

setObject:forKey:

Adds a given key-value pair to the dictionary.

- (void)setObject:(id)anObject forKey:(id)aKey

Again

setValue:forKey:

Adds a given key-value pair to the dictionary.

- (void)setValue:(id)value forKey:(NSString *)key

Then what is the difference in between them? Is the difference only in receiving parameters? can setObject:forKey: be used instead of setValue:forKey: ?

Community
  • 1
  • 1
itsazzad
  • 6,868
  • 7
  • 69
  • 89
  • 2
    possible duplicate of [1](http://stackoverflow.com/questions/1249634/wheres-the-difference-between-setobjectforkey-and-setvalueforkey-in-nsmutabl) [2](http://stackoverflow.com/questions/1062183/objective-c-whats-the-difference-between-objectforkey-and-valueforkey) – albertamg May 28 '11 at 12:05

1 Answers1

4

From the doc:

setValue:forKey:

Discussion
This method adds value and key to the dictionary using setObject:forKey:, unless value is nil in which case the method instead attempts to remove key using removeObjectForKey:.

setObject:forKey:

Important
Raises an NSInvalidArgumentException if aKey or anObject is nil. If you need to represent a nil value in the dictionary, use NSNull.

If aKey already exists in the dictionary, the dictionary’s previous value object for that key is sent a release message and anObject takes its place.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Andrew
  • 24,218
  • 13
  • 61
  • 90