objective c - The operation couldn’t be completed. No such file or directory: but the file exists -


i weird issue while saving file writetofile:options:error: in first case following issue:

writetofile failed error error domain=nscocoaerrordomain code=4 "the file “preferences.plist” doesn’t exist." userinfo=0xa12c30 {nsfilepath=file:/users/patrick/desktop/untitled.fef/preferences.plist, nsunderlyingerror=0xa0d130 "the operation couldn’t completed. no such file or directory"} 

but file exist in location. file stored in app document file package.

code: (subclass of nsdocument)

nsstring *preffile = [[[self fileurl] absolutestring] stringbyappendingpathcomponent:@"preferences.plist"];  nserror *error; bool succes = [[nskeyedarchiver archiveddatawithrootobject:documentpreferences] writetofile:preffile options:0 error:&error]; if (!succes) {     nslog(@"writetofile failed error %@", error); } 

make sure when using of ...tofilemethods of various classes use real path , not mistake file url. can tell these apart looking @ path. if path starts file://it can't used. if starts slash / regular file path. still might use nsfilemanager check if file exists.

as in code instead of calling absolutestring on self.fileurl call path.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -