I have a NSDictionary (parsed from JSON using JSONObjectWithData, if that’s relevant) that looks like:
{
ids = (
49939999,
44754859,
14424892,
16311801,
16045487,
31247745,
5982852
);
"next_cursor" = 0;
"next_cursor_str" = 0;
"previous_cursor" = 0;
"previous_cursor_str" = 0;
}
when logged using NSLog(@"%@", jsonResult);.
I’m accessing ids with friends = [jsonResult objectForKey:@"ids"];, and would expect friends to be of type NSArray, but apparently it’s of type __NSCFArray. Why?
I then try to get friends’ size using [friends count] but this creates an exception when run.
How to get count of a NSDictionary-stored “NSArray”?
UPDATE: Code
NSError *jsonError = nil;
id jsonResult = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&jsonError];
if (jsonResult != nil) {
self.friends = [jsonResult objectForKey:@"ids"];
NSLog(@"%@", self.friends);
NSLog(@"%@", [self.friends class]);
NSLog(@"%@", [self.friends count]);
dispatch_sync(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
NSCFArray is a subclass of NSArray. Most of the time when you deal with an NSArray, that’s the concrete class you’re dealing with. This is what it means in the documentation when it says NSArray is a class cluster.
Your crash is because when you try to print
[friends count], you use the format string@"%@".%@tells NSLog to expect an object, but this is an NSUInteger. Instead, you should doNSLog(@"%lu", (unsigned long)[friends count]). (If you’re not entirely clear on the idea of format specifiers, Apple has a handy guide.)