Iphone 无效的接收器类型int

Iphone 无效的接收器类型int,iphone,xcode,warnings,int,Iphone,Xcode,Warnings,Int,我似乎找不到这里有什么问题 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]%1

我似乎找不到这里有什么问题

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);
问题是:它工作并且“从”和“到”获得正确的值,但是我在指示的行中得到警告


有人知道为什么以及如何解决这个问题吗?(编译时不喜欢这些警告;)

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。

温度已经是
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必须只有4个数字,如3132(这是我得到的,如果我这样做我的方式),但如果我做了你的建议,我得到97759792,而不是…我没有对temp做任何更改。您是否检查过oneMove是否具有您期望的值?我想它应该是一个NSNumber对象。然后执行NSLog(“%d”,temp);看看这是否有效。否则,您的数据模型将被破坏。oneMove数组包含2个NSCFString对象。。。(和bestMoves数组一样)这可能对您的分析有帮助吗?顺便说一句:这个int-temp=[[[oneMove objectAtIndex:0]intValue]intValue];给我同样正确的结果。。。但还是有无效的接收器…谢谢!你的答案肯定是正确的,但我的问题是从别的地方开始的;)分离的sting是这样组成的[NSString stringWithFormat:@“%d,%d”,[possibleMoves objectAtIndex:i],wert];实际上应该是这样的:[NSString stringWithFormat:@“%d,%d”,[[possibleMoves objectAtIndex:i]intValue],wert];无论如何谢谢你!你帮我找到了正确的轨道!我试过了,但结果不对。temp必须只有4个数字,如3132(这是我得到的,如果我这样做我的方式),但如果我做了你的建议,我得到97759792,而不是…我没有对temp做任何更改。您是否检查过oneMove是否具有您期望的值?我想它应该是一个NSNumber对象。然后执行NSLog(“%d”,temp);看看这是否有效。否则,您的数据模型将被破坏。oneMove数组包含2个NSCFString对象。。。(和bestMoves数组一样)这可能对您的分析有帮助吗?顺便说一句:这个int-temp=[[[oneMove objectAtIndex:0]intValue]intValue];给我同样正确的结果。。。但还是有无效的接收器…谢谢!你的答案肯定是正确的,但我的问题是从别的地方开始的;)分离的sting是这样组成的[NSString stringWithFormat:@“%d,%d”,[possibleMoves objectAtIndex:i],wert];实际上应该是这样的:[NSString stringWithFormat:@“%d,%d”,[[possibleMoves objectAtIndex:i]intValue],wert];无论如何谢谢你!你帮我找到了正确的轨道!