Since the update to Xcode 5.1 I can't archive my project any more. Xcode always says "Multiple methods named "count" found with mismatched result, parameter type or attributes. This problem is new and simulator and running on device works fine. Here is the code:
for ( int i = 0; i<[parseJSONArray count];i++){
for (int j = 0; j<[JSON[@"data"][@"menu"][i][@"item"] count];j++){
[pictureURL addObject:JSON[@"data"][@"menu"][i][@"item"][j][@"image"]];
}
}
Xcode shows the error at this point : [JSON[@"data"][@"menu"][i][@"item"] count]
JSON
is a NSDictionary
.
Whats wrong with this?
try with like this
you need to passing
type of NSArray
Since there are multiple Cocoa classes with a method named
count
, andobjectForKeyedSubscript:
(to whichJSON[@"data"][@"menu"][i][@"item"]
resolves) returnsid
, the compiler can't do the typechecking it wants to do for the message send.To stop the warning, you'll need to cast the result of
JSON[@"data"][@"menu"][i][@"item"]
to its actual class e.g.,(NSDictionary *)(JSON[@"data"][@"menu"][i][@"item"])
, or put it into a temporary variable:NSDictionary * itemDict = JSON[@"data"][@"menu"][i][@"item"];
Ask yourself: What is the type of JSON[@"data"][@"menu"][i][@"item"] ? It is "id". The compiler doesn't know which method this object responds to. You send a "count" message. The compiler goes through all the count methods of all classes that it knows about. If there are more than two different ones, it has to complain.
You could write
More readable, easier to follow, runs faster, and easier to debug.
Of course you can also write
Just a cast like:
float a = [[_myArray objectForKey:@"myKey"] count] / 5.0;
float a = [(NSArray *)[_myArray objectForKey:@"myKey"] count] / 5.0;
In case you don't want to write code like this [((NSArray*)aId) count]:
Using arrayElementCount instead of 'count'
Try:
That help?