iphone - Why doesen't it work to write this NSMutableArray to a plist? -


edited.

hey, trying write nsmutablearray plist. compiler not show errors, not write plist anyway. have tried on real device too, not simulator.

basically, code does, when click accessoryview of uitableviewcell, gets indexpath pressed, edits nsmutablearray , tries write nsmutablearray plist. reloads arrays mentioned (from multiple plists) , reloads data in uitableview arrays.

code:

nsindexpath *indexpath = [table indexpathforrowatpoint:[[[event touchesforview:sender] anyobject] locationinview:table]];  [arrayfav removeobjectatindex:[arrayfav indexofobject:[nsnumber numberwithint:[[arraysub objectatindex:indexpath.row] intvalue]]]];  nsstring *rootpath = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) objectatindex:0]; nsstring *plistpath = [rootpath stringbyappendingpathcomponent:@"arrayfav.plist"]; nslog(@"%@ - %@", rootpath, plistpath);    [arrayfav writetofile:plistpath atomically:yes];      // reloads data arrays [self loaddatafromplists];  // reloads data in tableview arrays [tablefarts reloaddata]; 

cfshow() on array after removing 1 of them shows this:

<cfarray 0x6262110 [0x2c810a0]>{type = mutable-small, count = 4, values = (     0 : <cfnumber 0x6502e10 [0x2c810a0]>{value = +3, type = kcfnumbersint32type}     1 : <cfnumber 0x6239de0 [0x2c810a0]>{value = +8, type = kcfnumbersint32type}     2 : <cfnumber 0x6239dc0 [0x2c810a0]>{value = +10, type = kcfnumbersint32type}     3 : <cfnumber 0x6261420 [0x2c810a0]>{value = +40, type = kcfnumbersint64type} 

debug-info: writetoplist shows yes, have tried release arrays before filling them again, setting them nil, set atomically no.

as discussed in comments below, actual problem here plist being read , written 2 different locations. somewhere in app, there code reads file array similar this:

nsstring *plistfavpath = [[nsbundle mainbundle] pathforresource:@"arrayfav"                                                           oftype:@"plist"];  arrayfav = [[nsmutablearray alloc] initwithcontentsoffile:plistfavpath]; 

this logic reads array application's bundle, read-only location , part of distributed app. later when edited array persisted, code similar used:

nsstring *rootpath = [nssearchpathfordirectoriesindomains(nsdocumentdirectory,                                                           nsuserdomainmask,                                                           yes) objectatindex:0]; nsstring *plistpath = [rootpath                            stringbyappendingpathcomponent:@"arrayfav.plist"]; nslog(@"%@ - %@", rootpath, plistpath);  [arrayfav writetofile:plistpath atomically:yes];    

the result here updated file gets written app's documents directory, never read there, giving appearance file not being saved correctly. correct this, should change code reads file use same path writing to.

if need distribute default version of plist use on initial launch before array has been edited, continue include version of file in bundle , add code app delegate check if file exists in documents directory , if not present, copies bundle's default version of file proper place.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -