I’ve resolved an error some of my users were experiencing whenever my app loads JSON from Twitter:
-[__NSCFString objectForKey:] unrecognized selector
After researching, I believe the problem was the result of using an NSDictionary instead of an NSArray. My question, however, is why would some users with the EXACT same device and iOS version experience the error intermittently? Why wouldn’t it either error every time for everyone or never? Does this have to do with memory in use on the device or an interruption in receiving data from the server?
EDIT:
//I have since changed statuses to an NSArray
NSDictionary *statuses = [[NSDictionary alloc] init];
statuses = [output JSONValue];
for (NSDictionary *status in statuses)
{
Tweets *aTweet = [[Tweets alloc] init];
//error began (fatal error) on following line
aTweet.text = [status objectForKey:@"text"];
aTweet.created_at = [status objectForKey:@"created_at"];
aTweet.created_date = [dateImporter dateFromString:aTweet.created_at];
[self.tweets addObject:aTweet];
aTweet = nil;
}
It depends where the data in
outputis coming from. You assurme your JSON data is an array of dictionaries, but it’s possible that the server is returning something else, for example, if an error has occurred the server might return a dictionary with some error information in it.You’ll have to look at the Twitter API to see what data you might receive for this particular call.
https://dev.twitter.com/docs/error-codes-responses
Looking at the page above, you can use the HTTP return code to see if the request has failed, and if that’s the case, you can just abort this operation.