NSArray에서 값을 가져 오기 위해 값의 id 값으로 을 사용했습니다. 이제 그것을 2 차원 float 배열 [] []에 저장하려고합니다. 배열에 값을 할당하려고하면 할당 할 때 호환되지 않는 유형의 오류가 발생합니다. 값을 캐스팅하려고했지만 부동 소수점 값이 예상되는 곳에 포인터 값이 사용되었습니다. 값을 2 차원 배열에 저장해야합니다. 어떻게 만들 수 있습니까? 감사합니다. enemyDetal.txt에서 float 유형의 배열에 id 값을 저장할 수 있습니까?
@implementation fromFileRead1
NSString *fileNameString;
int numberOfEnemies, numberOfValues;
-(id)init
{
if((self = [super init]))
{
NSString *path = @"/Users/sridhar/Desktop/Projects/exampleOnFile2/enemyDetals.txt";
NSString *contentsOfFile = [[NSString alloc] initWithContentsOfFile:path];
NSArray *lines = [contentsOfFile componentsSeparatedByString:@"\n"];
numberOfEnemies = [lines count];
NSLog(@"The number of Lines: %d", numberOfEnemies);
for (id line in lines)
{
NSLog(@"Line %@", line);
NSString *string1 = line;
NSArray *split1 = [string1 componentsSeparatedByString:@","];
numberOfValues = [split1 count];
NSLog(@"The number of values in Row: %d", numberOfValues);
for (id value in split1)
{
NSLog(@"value %@", value);
float value1;
value1 = [split1 objectAtIndex:2]);
NSLog(@"VAlue of Value1 at index 2: %f", value1);
}
}
}
return self;
}
@end
나는 float 배열에서 객체 (예를 들어, ID)를 저장
1,3,3
2,3,2.8
10,2,1.6
일부 코드를 표시하십시오. –