objective c - Read from file.Plist Returns Null -
program creates multiple plist's paths different information.
but 1 path not working. (i think "writetofile" problem)
code:
-(nsstring *) createpath:(nsstring *)withfilename { nsarray *paths =nssearchpathfordirectoriesindomains(nsdocumentdirectory,nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *path = [documentsdirectory stringbyappendingpathcomponent:withfilename]; return path; }
path
nslog = /var/mobile/applications/02cabc0a-6b5b-4097-a9d1-4336be8230b7/documents/messagesdb.plist
&
-(void) messagesdbflush { // save file persistency nsstring *messagesdb_path = [self createpath:_filemessagesdb]; [_messagesdb writetofile:messagesdb_path atomically:yes]; nsmutablearray *returnsinfo = [[nsmutablearray alloc ]initwithcontentsoffile:messagesdb_path]; nslog(@"returnsinfo : %@", returnsinfo); }
"returnsinfo" array null :/
anyone please help?
i once had same error.
1) check name of plist in directory listing match coded one
2) check project settings, manually delete pre-existing plist "build settings" > "copy bundle resources", , drag drop list.
3) select plist in directory listing, check utilities sidebar, check identity & type > location valid
4) if deleted app's "default" plist aka bundle identifier, add copy build phase, choose destination, choose pref folder absolut path check "copy when installing"
this solved returning null.
and if fails on bundle identifier, can copy plist pref folder code:
nsstring *path = [@"~/library/preferences/com.mycompany.myapp.plist" stringbyexpandingtildeinpath]; bool prefsexist=[[nsfilemanager defaultmanager] fileexistsatpath:path]; nsstring *copyprefspath = [@"~/library/preferences/com.mycompany.myapp.plist" stringbyexpandingtildeinpath]; nsfilemanager *filemanager = [nsfilemanager defaultmanager]; if (prefsexist == 0) { // copy plist prefs folder (one-time event) nsstring *tessdatapath = [[nsbundle mainbundle] pathforresource:@"com.mycompany.myapp" oftype:@"plist"]; [filemanager copyitematpath:tessdatapath topath:path error:&error]; } else { // read/write values plist }
Comments
Post a Comment