2011-04-02 70 views
1

我已經完成了以下操作,將提取的請求放入數組數組中,但現在我不知道需要從chcsvparser調用哪些方法將其寫入csv文件試圖使用chcsvparser將coredata寫入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

寫CSV文件時,此網頁應該給你必要的信息和方法:

https://github.com/davedelong/CHCSVParser#readme

希望這有助於!

+0

謝謝我已經讀了幾次,但我不明白我需要調用哪些方法。 – lps 2011-04-02 16:47:15

+0

您是否嘗試過:writeToCSVFile:方法? – 2011-04-02 16:51:46

+0

我試過這樣但它字符串似乎是空的:\t [csvObjects writeToCSVFile:exportString atomically:NO]; \t NSLog(@「exportString%@」,exportString); – lps 2011-04-02 17:13:21

1

正如約翰建議,你應該使用writeToCSVFile:atomically:方便的方法。但是,請注意,如您在評論中描述的那樣使用它是不正確的。

您傳遞的NSString應該是您希望寫入數據的文件路徑。