初始化无需强制转换即可生成整数
我收到此警告,但我不知道如何解决它。我收到警告的行是
NSInteger thescore = [[myDictionary objectForKey:@"Score"] objectAtIndex:0];
If it make a Difference, myDictionary is a NSDictionary
Edit: 这是怎么回事?顺便说一句,我的数组是 NSMutableArray 而不是 NSArray
NSInteger thescore = [[myDictionary valueForKey:@"Score"] integerValue];
编辑 2: @Bvarious 提到我应该执行以下操作:
int thescore = [[myDictionary objectForKey:@"Score"] integerValue];
I get this warning and I am not sure how to fix it. The line where I get the warning is
NSInteger thescore = [[myDictionary objectForKey:@"Score"] objectAtIndex:0];
If it makes a difference, myDictionary is a NSDictionary
Edit: How is this? Btw my array is a NSMutableArray and not a NSArray
NSInteger thescore = [[myDictionary valueForKey:@"Score"] integerValue];
Edit 2: @Bavarious mentioned that I should do the following:
int thescore = [[myDictionary objectForKey:@"Score"] integerValue];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用
[someArray objectAtIndex:0]
的结果是一个对象。并且NSInteger
是一个原始类型:(cmd +双击 xcode 中的
NSInteger
以查看定义)我猜你可能实际上正在存储
NSNumber
数组中的对象。在这种情况下,你可以这样做The result of call
[someArray objectAtIndex:0]
is an object. AndNSInteger
is a primitive type:(cmd + double-click on
NSInteger
in xcode to see the definition)I guess you might actually be storing
NSNumber
objects in your array. In this case, you could do