【问题标题】:iOS: Converting id to intiOS:将 id 转换为 int
【发布时间】:2013-08-13 12:58:02
【问题描述】:

我在将对象的 id 转换为 int(或 NSINteger)时遇到了麻烦,以便以后可以在循环中使用它。

情况如下:

// "tasks" is a mutable array
int taskNo = [[tasks indexOfObject:@"something"] integerValue];

但结果是:

Bad receiver type 'NSUInteger' (aka 'unsigned int')

我发现了一个类似的线程,其代码类似于我上面的代码,但不幸的是它对我不起作用。我想我一定错过了一些简单的东西。

非常感谢!

【问题讨论】:

    标签: ios casting type-conversion


    【解决方案1】:
    int taskNo = (int)[tasks indexOfObject:@"something"];
    

    【讨论】:

    • 你第一个版本的答案是错误的,但现在它是正确的,我可以删除我的!
    • @cell 不要使用int,而应该使用unsigned intNSUInteger
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-25
    • 1970-01-01
    • 2013-08-03
    • 2019-06-18
    • 1970-01-01
    相关资源
    最近更新 更多