The method -writeData:
of NSFileHandle
class returns nothing. Is there any way for us to determine whether the operation is successful or not? Or I should use other way to save my data?
Asked
Active
Viewed 539 times
0

Andrew Chang
- 1,289
- 1
- 18
- 38
-
What do you need to save? NSData? – d00dle Oct 10 '13 at 07:13
-
Yes. I want the "seekToFile", too. And this is why I use NSFileHandle Class. Or should I implement a class myself calling low-level system API like `fseek()`, `fwrite()`, etc? – Andrew Chang Oct 11 '13 at 01:04
2 Answers
0
According to writeData method Reference, this method raises an exception if the file descriptor is closed or is not valid, if the receiver represents an unconnected pipe or socket endpoint, if no free space is left on the file system, or if any other writing error occurs.

Suryakant Sharma
- 3,852
- 1
- 25
- 47
-
Thanks for you reply. I add comment in my question. And that also explains why I did not use `-writeToFile:` method. – Andrew Chang Oct 11 '13 at 01:05
0
You can write any standard cocoa object to a file pretty simple. This returns a BOOL value if it is sucessful or not
BOOL result = [YOUR_OBJECT writeToFile:@"absolute/file/path" atomically:YES]];
if (result)
NSLog(@"All went well");
else
NSLog(@"File was not saved");

d00dle
- 1,276
- 1
- 20
- 33