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: enter image description here

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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -