A CHCSVWriter has several methods for creating CSV files:
-writeField: takes an object and writes its -description (after proper escaping) to a CSV file. He will also write a field delimiter (,) if necessary. You can pass an empty string (@ "") or nil to write an empty field.
-writeFields: takes a list of comma-delimited and nil-terminated objects and sends them to -writeField :.
-writeLine used to end the current CSV line. If you do not call -writeLine, then all of your CSV fields will be on the same line.
-writeLineOfFields: takes a list of comma-delimited and nil-terminated objects, sends them to -writeField :, and then calls -writeLine.
-writeLineWithFields: takes an array of objects, sends each of them to -writeField :, and then calls -writeLine.
-writeCommentLine: takes a line and writes it to a file as a CSV-style comment.
In addition to writing to a file, CHCSVWriter can be initialized to write directly to NSString .
Something like this should work for you.
CHCSVWriter *writer = [[CHCSVWriter alloc] initForWritingToString]; for (NoteLog *noteInfo in fetchedObjects) { [writer writeLineOfFields:noteInfo.city, noteInfo.country, noteInfo.datetime, noteInfo.notelatitude, noteInfo.notelongtitude, noteInfo.state, noteInfo.text, nil]; } NSLog(@"My CSV File: %@",writer.stringValue);
source share