I am trying to open a file for writing to it. The file may not exist.
I found that [NSFileHandle fileHandleForWritingAtPath:filePath] returns nil if the file does not exist. Having googled, I found code snippets like this
[[NSData data] writeToFile:filePath atomically:YES]
which, I think, guarantees the existence of the file before opening it.
My questions are: is the last line of code the recommended way to create a file? It seems strange that NSFileHandle does not have a routine to create a new file (and can only work with existing files).
source share