Search code examples
iphonensfilemanager

iphone NSFilemanager not creating file


I'm using NSFileManager to create a file at a specified path with text view contents. I'm using following code

[[NSFileManager defaultManager] createFileAtPath:saveFileName contents:[[tView text] dataUsingEncoding:NSASCIIStringEncoding] attributes:nil];

But the problem is that, its creating file with no contents. I'm sure that text contents are not nil. How can I check and confirm that data is written into file.


Solution

  • Some suggestions:

    1. Capture the BOOL return of the line to make sure it is completing.
    2. Log the value of [tView text] to make sure it is not empty.
    3. ASCII encoding can cause problems these days. Try NSUTF8StringEncoding or NSUTF16StringEncoding.

    Localization may be a problem with plain ASCII encoding because ASCII does not handle multibyte character encodings.