Why is a NSString @"@"
not Key Value Compliant?
Are there other strings that aren't compliant as well?
You can try that it is failing with this code for example:
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:@"Some Object" forKey:@"@"];
NSString *theObject = [dict valueForKey:@"@"];
Setting it as a key is ok but not querying for that key.. Sure you can work around this error by appending some other string you later on remove another time like doing the following when you want to have the key @:
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:@"Some Object" forKey:@"keyConst@"];
NSString *theObject = [dict valueForKey:@"keyConst@"];
The counterpart to
setObject:forKey:
isobjectForKey:
(and notvalueForKey:
) to retrieve an item from a dictionary:Alternatively, use the "new" dictionary subscripting syntax:
valueForKey:
uses Key-Value coding methods if the key starts with@
. From the documentation of-[NSDictionary valueForKey:]
:For example,
does the same as
So in almost all cases, you should use
objectForKey:
, unless you explicitly want to do some Key-Value coding magic.