We have had countless problems with JSON feeds causing [__NSCFString objectForKey:] errors when processed (using AFNetworking JSON Framework) that crash the application.
We are aware why this is, since a string takes up the place where an NSDictionary is expected.
But I was thinking, isn’t it possible to make a category or subclass of the objectForKey function that makes a quick check to see if the object in question is a Dictionary at all ? Same thing would be lovely to have on ObjectForKey on NSArrays.
This would definately reduce the risk of problems like this reoccurring in our projects.
I don’t think it would be too hard to have a few functions like…
You could do something like…
You could have similar ones for other object types too.
That way you always receive the type of object you are expecting or nil.
EDIT
In fact, after doing some searching. I think this function already exists for NSDictionary. (Correction thanks to jrturton. This exists only for NSUserDefaults.)