views:

35

answers:

1

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.

+2  A: 

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.

TechZen