NSDictionary 和关于“不带强制转换的整数指针”的警告
我看到有很多关于这个主题的帖子,但我的脑海中没有找到解决方案。这是我的问题:
double var = [[variables objectForKey:[value characterAtIndex:1]] doubleValue];
变量是一个 NSDictionary。在这种情况下,value
是一个NSString
,我需要characterAtIndex:1
,因为我在字符串前面添加了一个特殊的指示符。在英语中,我想根据此 NSString
键从我的 NSDictionary
获取值,但在构建时收到此警告:
警告:传递“objectForKey:”的参数 1 使指针来自整数而不进行强制转换
I see that there is a bunch of posts on this topic, but a solution is not clicking in my head. Here is my issue:
double var = [[variables objectForKey:[value characterAtIndex:1]] doubleValue];
variables is an NSDictionary
. value
in this situation is an NSString
and I need characterAtIndex:1
because I prepended the string with a special designator. In English, I want to get a value from my NSDictionary
based on this NSString
key, but I get this warning when building:
warning: passing argument 1 of 'objectForKey:' makes pointer from integer without a cast
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
characterAtIndex:
返回一个 unichar,而不是一个对象,而 NSDictionary 键必须是对象。听起来您想要类似[value substringToIndex:1]
的内容。characterAtIndex:
returns a unichar, not an object, while NSDictionary keys must be objects. It sounds like you want something like[value substringToIndex:1]
.