Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fails, but no error object is returned. Why?

I'm trying to understand the meaning of the value returned by [NSData writeToFile:options:error:]. The method returns a BOOL, which according to Apple's documentation is "YES if the operation succeeds, otherwise NO."

Fair enough, but if it's NO, I would have assumed that the error parameter would then be set to some retrievable NSError* value. However in results I'm coming across, that's not the case. Accordingly I'm somewhat confused, and don't know how to determine what caused the failure.

To wit, I've got this code (more or less):

NSError* error = nil;
BOOL success = [data writeToFile: filePath error: &error];
if ( error )
    NSLog( @"error = %@", [error description] );

success turns out to be NO in the code I'm running, but the NSLog statement is never executed. How come?

Howard

like image 743
hkatz Avatar asked Aug 11 '09 20:08

hkatz


1 Answers

It's possible that data is nil, in which case [data writeToFile:error:] returns nil, but *error is not set.

like image 159
Barry Wark Avatar answered Oct 17 '22 00:10

Barry Wark