称为“计数”的多个方法发现具有不匹配的结果,参数类型或属性 [英] Multiple methods named "count" found with mismatched result, parameter type or attributes

查看:741
本文介绍了称为“计数”的多个方法发现具有不匹配的结果,参数类型或属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从更新Xcode 5.1以后,我不能再存档我的项目了。 Xcode总是说多个方法命名计数发现不匹配的结果,参数类型或属性。这个问题是新的,模拟器和运行在设备上的工作正常。这是代码:

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显示此时的错误: [JSON [@data] [@menu] [i] [@item] count] JSON 是一个 NSDictionary
这是什么问题?

Xcode shows the error at this point : [JSON[@"data"][@"menu"][i][@"item"] count] JSON is a NSDictionary. Whats wrong with this?

推荐答案

问自己: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.

您可以写

NSDictionary* data = JSON [@"data"];
NSArray* menu = data [@"menu"];
NSDictionary* menuI = menu [i];
NSArray* item = menuI [@"item"];

for (NSDictionary* picture in item)
    [pictureURL addObject:picture [@"image"];

更易读,更容易遵循,运行速度更快,更易于调试。

More readable, easier to follow, runs faster, and easier to debug.

当然,您也可以写

for (NSUInteger j = 0; j < item.count; ++j)
{
    NSDictionary* picture = item [i];
    [pictureURL addObject:picture [@"image"];
}

这篇关于称为“计数”的多个方法发现具有不匹配的结果,参数类型或属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆