Reputation: 1586
I am Creating a NSDictionary and adding a key value pair as below
NSDictionary* dictionary = @{ @0: @"I am the value" };
and retrieving the value as below
NSString* value = [dictionary valueForKey:@0];
Application crashed for doing this, I don't understand the reason, I am giving the same data type and value.
What is the datatype of @0, I guess it is NSNumber, If not correct me.
Upvotes: 2
Views: 8068
Reputation: 3456
valueForKey: is not the proper method for what you are trying to achieve.
you should use:
NSString* value = [dictionary objectForKey:@0];
ValueForKey is for key value coding and expect a NSString as parameters
Upvotes: 1
Reputation: 52163
Yes, it's NSNumber
type however the problem is somewhere else.
You should call objectForKey
instead of valueForKey
which is mainly used for KVO.
NSString *value = [dictionary objectForKey:@0];
or better:
NSString *value = dictionary[@0];
Upvotes: 7