I am really struggling to find how one creates a file that doesn't already exist in Objective-C, and then use that file write data. In C, one uses a fopen command, usually wrapped in an if statement to catch a failure...
if ((file_pointer = fopen(file_name, "wb")) == NULL) {
fprintf(stderr, "could not create file.\n");
exit(EXIT_FAILURE);
}
You have created a file, and you have a file_pointer to use as you write data to your file ... fprintf(file_pointer, %d, someInt); So easy.
With Objective-C and Xcode... I'm already getting the feeling like there's many ways to skin a cat... but I can't get any of them to work for me.
I see some people use an NSData method...
BOOL written = [dataBuffer writeToFile:destinationPath options:0 error:NULL]; //assumes a NSData file *dataBuffer and NSString *destinationPath.
But this doesn't work, no file is actually created.
I also tried:
NSFileHandle *file;
NSData *data = [...
file = [NSFileHandle fileHandleForUpdatingAtPath: @"/tmp/filename.xyz"];
[file writeData: data];
But this also failed to create a file. There also seems to be a whole other trajectory using NSFileManager and a "createFileAtPath" method, which I ALSO could not get to work.
HELP! What am I missing?