【问题标题】:GKScore properties warningGKScore 属性警告
【发布时间】:2011-07-30 18:45:48
【问题描述】:

我正在为 Game Center 构建一个自定义显示,它可以工作,但我收到以下代码的警告 -

NSMutableArray *playerIDsArray = [[NSMutableArray alloc] init];
[highScores removeAllObjects];

for (GKScore *thisScore in scores)
             {
                 NSMutableDictionary *thisEntry = [[NSMutableDictionary alloc] init];
                 NSString *playerID = [thisScore playerID];
                 [thisEntry setObject:playerID forKey:@"playerID"];
                 [playerIDsArray addObject:playerID];
                 [thisEntry setObject:[NSNumber numberWithInt:(int)[thisScore value]] forKey:@"value"];
                 [highScores setObject:thisEntry forKey:[NSString stringWithFormat:@"%i",[thisScore rank]]]; // warning here
                 [thisEntry release];
             }

[thisScore rank] 的警告显示“未找到方法 '-rank'(返回类型默认为 'id')”。但是,代码工作正常。我一定是错过了什么……

任何帮助表示赞赏!

【问题讨论】:

    标签: iphone objective-c xcode warnings gamekit


    【解决方案1】:

    在 GKScore 中,rank 是一个 NSInteger aka Object...

    调用 %i 是调用整数..

    因此..你必须调用[[thisScore rank]intValue]来获取NSInteger对象的整数值..

    【讨论】:

    • 对不起 - 没有任何区别,仍然收到相同的警告
    • ok.. 嗯.. rank 不是一种方法.. 它是一个属性.. [[thisScore.rank]intValue]
    【解决方案2】:

    终于弄明白了——真的有点傻,我只是没有包括这个——

    #import <GameKit/GKScore.h>
    

    我只是假设它已被导入其他 Game Center 标头所覆盖...无论如何谢谢!

    【讨论】:

      猜你喜欢
      • 2017-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      • 2021-09-22
      • 2020-01-11
      • 2013-10-11
      相关资源
      最近更新 更多