objective c - Proper way of handling reference to NSError -
my code looks this, app crashes on last line, when tries log error. doing wrong?
bool isdir; nserror *error; nsstring *downloadpath = [[nsstring stringwithformat:@"%@/%@", [download downloadfolder], [download escapedtitle]] stringbyexpandingtildeinpath]; nsfilemanager *filemanager = [nsfilemanager defaultmanager]; if (![filemanager fileexistsatpath:downloadpath isdirectory:&isdir]) { [filemanager createdirectoryatpath:downloadpath withintermediatedirectories:yes attributes:nil error:&error]; if (error) nslog(@"%@", [error localizeddescription]); }
i've attached output console:
in cocoa, nserror **
valid if called method returns error, in case if -createdirectoryatpath:...
returns false.
instead of testing if (error)
, test return value of -createdirectoryatpath:
method being false, , you'll go.
for example:
if (![filemanager createdirectoryatpath:downloadpath withintermediatedirectories:yes attributes:nil error:&error]) { nslog(@"%@", [error localizeddescription]); }
Comments
Post a Comment