I want to modify (Add a new row) existing csv file in xcode. i have created a csv file programmatically , but when i try to modify it , it delete all the previos data.
i am opening an existing csv file and want to add a next row.
NSString *docFile = [DOCS_FOLDER stringByAppendingPathComponent:@"Questions_Logs.csv"]; NSFileManager* filemanager = [NSFileManager defaultManager];
//---get the contents of file and if content avalbl than append new data and save it--
if ([filemanager fileExistsAtPath:docFile])
{
NSArray *arrCSV = [NSArray arrayWithObjects:strName,strAge,strDesig, nil];
[[arrCSV componentsJoinedByString:@","] writeToFile:docFile atomically:YES encoding:NSUTF8StringEncoding error:NULL];
}
else
{ NSArray *arrCSV = [NSArray arrayWithObjects:@"Name",@"Age",@"Designation", nil]; [[arrCSV componentsJoinedByString:@","] writeToFile:docFile atomically:YES encoding:NSUTF8StringEncoding error:NULL]; }