bruno
bruno

Reputation: 2169

NSMutableDictionary removeObjectForKey strange behaviour

If i set an object in a NSMutableDictionary this way:

NSString* idFriend = @"Superman";
[reqWaitDictionary setObject:[NSNumber numberWithBool:YES] forKey:idFriend];

It doesn't work when i try to remove it like this:

[reqWaitDictionary removeObjectForKey:idFriend];

In order for it to work, i have to set the NSMutableDictionary this way:

[reqWaitDictionary setObject:[NSNumber numberWithBool:YES] forKey:[NSString stringWithFormat:@"%@",idFriend]];

For me this is strange because the idFriend is already a NSString. Anyone knows why?

Upvotes: 1

Views: 891

Answers (1)

Rajesh Loganathan
Rajesh Loganathan

Reputation: 11217

Both will works fine if you declare correctly. Declaration type only different.

Try like this:

[reqWaitDictionary setObject:idFriend forKey:@"someKey"];

Upvotes: 1

Related Questions