Arrays 将NSMutableArray转换为浮点数组
我有一根带lat和lon的绳子,用“,”隔开:Arrays 将NSMutableArray转换为浮点数组,arrays,nsmutablearray,parameter-passing,Arrays,Nsmutablearray,Parameter Passing,我有一根带lat和lon的绳子,用“,”隔开: NSArray*coord=[newString componentsSeparatedByString:@“,”]; NSMutableArray*lat=[[NSMutableArray alloc]init]; NSMutableArray*lon=[[NSMutableArray alloc]init]; 对于(int i=0;itesty)!=(维蒂[j]>暴躁)&& (testx
NSArray*coord=[newString componentsSeparatedByString:@“,”];
NSMutableArray*lat=[[NSMutableArray alloc]init];
NSMutableArray*lon=[[NSMutableArray alloc]init];
对于(int i=0;itesty)!=(维蒂[j]>暴躁)&&
(testx<(vertx[j]-vertx[i])*(testy-verty[i])/(verty[j]-verty[i])+vertx[i]))
c=!C
}
返回c;
}
因此NSMutableArray无法工作。所以我创造了这个:
//Seperating the string with coordinates by ","
NSArray* coord = [newString componentsSeparatedByString:@","];
float *lat = malloc(sizeof(float) * ([coord count]/2));
float *lon = malloc(sizeof(float) * ([coord count]/2));
for(int i=0;i<[coord count]-1;i=i+2)
{
lat[i]= [[coord objectAtIndex:i] floatValue];
lon[i]= [[coord objectAtIndex:i+1] floatValue];
}
free(lat);
free(lon);
//用“,”分隔带坐标的字符串
NSArray*coord=[newString组件由字符串分隔:@“,”];
浮动*lat=malloc(浮动大小)*([coord count]/2));
float*lon=malloc(sizeof(float)*([coord count]/2));
对于(int i=0;i我想您希望使用数组中的值
要获得这样的值,可以使用objectAtIndex,如:
[arrayName objectAtIndex:index];
如果您真的想将NSMutableArray作为参数,您应该这样做:
functionName:(NSMutableArray*)arrayName
如果提供了其他信息,我想您需要这个
考虑到您已经建立了NSMUTABLEARRY*lat和NSMUTABLEARRY*lon
其中lat和lon的值不等于零或null
for(int i=0;i<lat.count;i++)
{
pnpoly(lat.count, [lat objectAtIndex:i], [lon objectAtIndex:i], static, static);
}
for(int i=0;i实际上我不想更改函数。用[vert objectAtIndex:j]替换verity[j]时会出现错误@user776720您现在正在抓取一本好的C语言书并阅读它。然后用Objective-C语言书重复。float
s不是对象。lat[i]=[[coord objectAtIndex:i]floatValue];对象可以转换为floats您应该检查j是否小于数组的长度。您还应该检查数组是否正确初始化
//Seperating the string with coordinates by ","
NSArray* coord = [newString componentsSeparatedByString:@","];
float *lat = malloc(sizeof(float) * ([coord count]/2));
float *lon = malloc(sizeof(float) * ([coord count]/2));
for(int i=0;i<[coord count]-1;i=i+2)
{
lat[i]= [[coord objectAtIndex:i] floatValue];
lon[i]= [[coord objectAtIndex:i+1] floatValue];
}
free(lat);
free(lon);
for(int i=0;i<lat.count;i++)
{
pnpoly(lat.count, [lat objectAtIndex:i], [lon objectAtIndex:i], static, static);
}