In Cocoa, the NSError **
is only valid if the called method returns an error, which in this case would be if -createDirectoryAtPath:...
returns false.
Instead of testing for if (error)
, test for the return value of the -createDirectoryAtPath:
method being false, and you'll be good to go.
For example:
if (![fileManager createDirectoryAtPath:downloadPath withIntermediateDirectories:YES attributes:nil error:&error]) {
NSLog(@"%@", [error localizedDescription]);
}