接收器类型 int 无效

发布于 2024-09-08 03:18:42 字数 433 浏览 7 评论 0 原文

我似乎找不到这里的问题...

NSArray *oneMove;
oneMove = [[bestMoves objectAtIndex:i] componentsSeparatedByString:@","];
int from, to;
int temp = [[oneMove objectAtIndex:0] intValue];

from = [temp intValue]/100; //"Invalid receiver type int"
to = [temp intValue]%100;   //"Invalid receiver type int"

NSLog(@"%d, %d", from, to);

问题是:它有效,“从”和“到”得到正确的值,但我在指定的行收到警告...

任何人都知道为什么以及如何修复那? (不喜欢编译时的警告;))

I cant seem to find what would be the problem here...

NSArray *oneMove;
oneMove = [[bestMoves objectAtIndex:i] componentsSeparatedByString:@","];
int from, to;
int temp = [[oneMove objectAtIndex:0] intValue];

from = [temp intValue]/100; //"Invalid receiver type int"
to = [temp intValue]%100;   //"Invalid receiver type int"

NSLog(@"%d, %d", from, to);

The thing is: it works and 'from' and 'to' get the right values but i get warnings at the indicated lines...

anyone knows why and how to fix that? (dont like them warnings when compiling ;) )

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

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

发布评论

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

评论(1

葬花如无物 2024-09-15 03:18:42

temp 已经是 int 值,没有 NSNumber。因此您无法向其发送 [temp intValue] 消息。

只需使用

from = temp / 100;
to = temp % 100;

编辑: 下面是证明其有效的代码:

NSArray *bestMoves = [NSArray arrayWithObject:@"499,340,124"]; // Example data
NSArray *oneMove  = [[bestMoves objectAtIndex:0] componentsSeparatedByString:@","];
int from, to;
int temp = [[oneMove objectAtIndex:0] intValue];

from = temp/100; // Code change
to = temp%100;   // Code change

NSLog(@"%d, %d", from, to);

输出符合预期 4, 99。

temp is already int value, no NSNumber. So you cannot send an [temp intValue] message to it.

Just use

from = temp / 100;
to = temp % 100;

Edit: Here is code that proves it works:

NSArray *bestMoves = [NSArray arrayWithObject:@"499,340,124"]; // Example data
NSArray *oneMove  = [[bestMoves objectAtIndex:0] componentsSeparatedByString:@","];
int from, to;
int temp = [[oneMove objectAtIndex:0] intValue];

from = temp/100; // Code change
to = temp%100;   // Code change

NSLog(@"%d, %d", from, to);

Output is as expected 4, 99.

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