I set a breakpoint...
if I do:
(lldb) print [self dictionary]
(NSDictionary *) $5 = 0x0945c760 1 key/value pair
but if I do:
(lldb) print [[self dictionary] allKeys]
error: no known method '-allKeys'; cast the message send to the method's return type
error: 1 errors parsing expression
Even if I try to access the key that I know is in there..
(lldb) print [[self dictionary] objectForKey:@"foobar"]
error: no known method '-objectForKey:'; cast the message send to the method's return type
error: 1 errors parsing expression
What am I doing wrong?
error: no known method '-objectForKey:'; cast the message send to the method's return type
So, it tells you it can't deduce return type information merely from the name of the message send - and that's perfectly fine. And it even tells you how exactly you have to resolve that problem - you have to cast the message send to the method's return type.
Firing up Apple's docs, we find out that - [NSDictionary objectForKey:]
returns id
- the generic Objective-C object type. Casting to id (or even better, if you know what types of objects your dictionary holds, casting to that exact object type) does the trick:
(lldb) print (MyObject *)[(NSDictionary *)[self dictionary] objectForKey:@"foobar"]