我通过NSNumber
在四个不同的数组中格式化 s 创建一个很长的字符串:
NSString *datos = @"";
for (NSInteger counter = 0; counter < [latOut count]; counter++) {
datos = [datos stringByAppendingString:[NSString stringWithFormat:@"%.0005f,", [[latOut objectAtIndex:counter] floatValue]]];
datos = [datos stringByAppendingString:[NSString stringWithFormat:@"%.0005f,", [[lonOut objectAtIndex:counter] floatValue]]];
datos = [datos stringByAppendingString:[NSString stringWithFormat:@"%ld,", [[tipoOut objectAtIndex:counter] integerValue]]];
datos = [datos stringByAppendingString:[NSString stringWithFormat:@"%ld\n", [[velocidadOut objectAtIndex:counter] integerValue]]];
}
NSString *curDir = [[NSFileManager defaultManager] currentDirectoryPath];
NSString *path = @"";
path = [path stringByAppendingPathComponent:curDir];
path = [path stringByAppendingPathComponent:@"data.csv"];
// Y luego lo grabamos
[datos writeToFile:path atomically:YES encoding:NSASCIIStringEncoding error:&error];
计数为 18,000 个条目,此循环需要将近 2 分钟才能完成。
我怎样才能让这更快?