GKScore 属性警告

发布于 2024-10-30 11:45:29 字数 868 浏览 1 评论 0原文

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

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];
             }

[thisScorerank] 的警告说“找不到方法'-rank'(返回类型默认为'id') )”。不过,该代码运行良好。我一定错过了一些东西...

任何帮助表示赞赏!

I'm building a custom display for Game Center, which works, except I'm getting a warning for the following code -

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];
             }

The warning for [thisScore rank] says "Method '-rank' not found (return type defaults to 'id')". The code works fine, however. I must be missing something...

Any help appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花开雨落又逢春i 2024-11-06 11:45:29

在 GKScore 中,rank 是一个 NSInteger 又名对象...

而调用 %i 是调用整数..

因此..您必须调用 [[thisScorerank]intValue] 来获取 NSInteger 的整数值目的..

in GKScore, rank is a NSInteger aka Object...

Where as calling %i is calling integer..

hence.. You must call [[thisScore rank]intValue] to get the integer Value of the NSInteger Object..

苦笑流年记忆 2024-11-06 11:45:29

终于弄清楚了 - 真的有点傻,我只是没有包含这个 -

#import <GameKit/GKScore.h>

我只是假设它是通过导入其他游戏中心标头来覆盖的......无论如何谢谢!

Finally figured it out - bit daft really, I just hadn't included this -

#import <GameKit/GKScore.h>

I'd just assumed it was covered by importing the other Game Center headers... Thanks anyway!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文