I have three arrays. The first array contains strings, same as the second, however the third one contains NSNumber
\'s. Anyways, back on topic... how can I creat
NSArray *firstArray, *secondArray, *thirdArray;
NSMutableString *csv = [NSMutableString stringWithString:@"Name,Date,Miles"];
NSUInteger count = [firstArray count];
// provided all arrays are of the same length
for (NSUInteger i=0; i<count; i++ ) {
[csv appendFormat:@"\n\"%@\",%@,\"%d\"",
[firstArray objectAtIndex:i],
[secondArray objectAtIndex:i],
[[thirdArray objectAtIndex:i] integerValue]
];
// instead of integerValue may be used intValue or other, it depends how array was created
}
NSString *yourFileName = @"your filename";
NSError *error;
BOOL res = [csv writeToFile:yourFileName atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (!res) {
NSLog(@"Error %@ while writing to file %@", [error localizedDescription], yourFileName );
}