While this isn't a problem, I wanted to hear if someone could please check the format string I use when I create an CSV file? It does work, but it looks kind of "weird" and was wondering if this was the optimal format?
These are the column headers:
NSMutableString *csv = [NSMutableString stringWithFormat:@"Title 1,Title 2,Title 3,Title 4,Title 5,Title 6,Title 7"];
Then I iterate over an array I have to populate the CSV file:
for (int i = 0; i < [myArray count]; i++)
{
[csv appendFormat:@"\n\"%@ %@%@ %@\",%@,%@,%@,%@,%@,\"%@\"",
@"value one", @"value two", @"value three", @"value four", // this is one column
@"Value one", // this is a new column
@"value two", // this is a new column
@"value three", // this is a new column
@"value four", // this is a new column
@"value five", // this is a new column
@"value six" // this is a new column
}
Then this is where I create the file and save it in the document directory:
NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [array lastObject];
NSString *fileName = [docDir stringByAppendingPathComponent:@"export_file.csv"];
NSError *error;
BOOL res = [csv writeToFile:fileName atomically:YES encoding:NSUTF8StringEncoding error:&error];
All of the "value x" strings are replaced by functions in this question for the sake of simplicity.
Is the format string correct, and is this a good way of creating a CSV file to add as attachment to a MFMailComposeViewController
's mail?
If I repeat this process without changing the file name, will it simply overwrite the existing file? It sure looks like it, but I just want to be sure.
for (MyObject *currentObject in myArray)
instead indeed. I just used the other type (the one in the question) during testing to log outi
in the loop. I'm just asking whether the format I'm using inappendFormat:
is correct, given the strings I provide underneath. The strings will only contain letters, no symbols. It'll create a table with 7 columns and x (array count) number of rows as a CSV format for use with excel or similar – Erik Aug 15 at 21:56