Search code examples
iosios5csvnsfilemanager

How to create a blank CSV file in iOS


I am trying to create a blank CSV file and then write to it using CHCSVWriter, but I do not see a method in the library to create a new file with no content. Is there something at the iOS level that I can use to do this?


Solution

  • Have you tried

    NSString *content = @"content here";
    NSData *fileContents = [content dataUsingEncoding:NSUTF8StringEncoding];
    [[NSFileManager defaultManager] createFileAtPath:@"/my/path/to/file.csv"
                                    contents:fileContents
                                    attributes:nil];
    

    if you want a blank file, try setting contents:nil