我已经完成了以下操作,将获取的请求放入数组数组中,但现在我不知道需要从chcsvparser调用哪些方法将其写入csv文件
NSArray *objectsForExport = [fetchedResultsController fetchedObjects];
NSArray *exportKeys = [NSArray arrayWithObjects:@"best_checkout", @"darts_thrown", @"high_score", @"score_100", @"score_140", @"score_180",@"three_dart_average",nil];
NSMutableArray *csvObjects = [NSMutableArray arrayWithCapacity:[objectsForExport count]];
for (NSManagedObject *object in objectsForExport) {
NSMutableArray *anObjectArray = [NSMutableArray arrayWithCapacity:[exportKeys count]];
for (NSString *key in exportKeys) {
id value = [object valueForKey:key];
if (!value) {
value = @"";
}
[anObjectArray addObject:[value description]];
}
[csvObjects addObject:anObjectArray];
}
答案 0 :(得分:1)
正如约翰所建议的那样,你应该使用writeToCSVFile:atomically:
便利方法。但是,请注意,在评论中描述的使用它是不正确的。
您传入的NSString应该是您希望数据写入的文件路径。
答案 1 :(得分:0)