我有以下函数,我正在努力将y值作为int值输出。
+ (NSMutableArray *) cleanPoints:(NSMutableArray *)pointsArray{
NSMutableArray *mutableArray = [NSMutableArray array];
for(int i = 0; i<pointsArray.count-1; i++){
CLog(@"pointsArray %@", pointsArray[i]); /// here it gives me the correct number, like 345
int y = (int)pointsArray[i]; //// here seems to be the problem
CLog(@"y = %d", y); ///// y is a weird number, like y = 384643392
if (y < 4 || y > -4){
y = 0;
}
//create Array
[mutableArray addObject:@(y)];
}
return mutableArray;
}
如果我从int y=(int(pointsArray[I]行中取出(int(,那么我会得到错误"无法用类型为'id'的右值初始化类型为'int'的变量
这一行毫无意义:
int y = (int)pointsArray[i];
NSArray不可能包含int
值。它只能包含对象,并且在Objective-C中,int
不是对象。
也许你的意思是
int y = [pointsArray[i] intValue];
(但我只是猜测这个NSArray包含NSNumber对象;我无法知道,因为你没有给出任何信息(