How to export a Core Data object to a CSV file

I want to export a Core Data object to a CSV file to save application data. I searched google but didn't find anything.

My application uses only one entity with five attributes. These attributes are all lines except one, which is a decimal number (with a semicolon or period). How can I export this object with all attributes?

+5
source share
1 answer

You need to create a method to perform this kind of operation, for example:

NSString *separator = @", ";
NSString *cvs = @"";
for (NSObject *object in arrayOfObject) {
        cvs = [NSString stringWithFormat:@"%@%@%@%@%@\n", cvs, [object att1], separator, [object att2], separator, [object att3]...];
}
//If you want to store in a file the CVS
[cvs writeToFile:pathToFile atomically:YES];

"" , , . stringWithFormat, var, , : Objective-C NSStrings

: https://github.com/davedelong/CHCSVParser , / CVS.

+7

All Articles