gpt4 book ai didi

ios - 使用NSInteger作为NSDictionary objectForKey中的类型ID

转载 作者:行者123 更新时间:2023-12-01 17:30:06 25 4
gpt4 key购买 nike

我正在尝试在indexPath.row中插入键值dictionary。当我只执行indexPath(不使用.row)时,它可以正常工作。但是,当我添加.row时,它给了我一个错误,说:

Implicit conversion of 'NSInteger' (aka 'long') to 'id' is disallowed with ARC

Incompatible integer to pointer conversion sending 'NSInteger (aka 'long') to paramater of type 'id'

这是我的代码:
[self.myDict objectForKey:indexPath.row];

然后,当我在它的末尾添加integerValue时,它仍然给我同样的错误。

最佳答案

NSDictionary只能处理对象,使用NSInteger作为键的一种简单方法是将其包装在NSNumber对象中:

[self.myDict objectForKey:[NSNumber numberWithInteger:indexPath.row]];

另外,使用NSNumber的更好方法是使用文字,例如:
[self.myDict objectForKey:@(indexPath.row)];

有关文字 here的更多信息。

关于ios - 使用NSInteger作为NSDictionary objectForKey中的类型ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29240011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com