iphone - Have a question about saving to plist -


i have .plist filled data ships app.

it's array of dictionaries other arrays/dictionaries in it.

the values take array , use in app may name, "computer".

i'm adding feature let user create own item, instead of choosing loading array. should save item same .plist, or create separate .plist each user?

then, how pull info both standard .plist , user created .plist , load them 1 tableview?

if you're writing ios, can't save same plist file because can't write application bundle.
1 thing save copy of plist application's documents folder, , modify same plist, way data unified in single file.
or can load original plist application bundle, make mutable copy of nsarray, load additional plist documents folder user's objects, , append them nsmutablearray calling addobjectsfromarray.
or can keep them in separate nsarray display them in table view 1 returning [originaldataarray count] + [userdataarray count] tableview:numberofrowsinsection: method of table view data source, , of course use appropriate data in tableview:cellforrowatindexpath: method.

edit:

about saving user data, don't have worry writing plist.
nsarray conforms nscoding protocol, , nsdictionary, means can save , load using nskeyedarchiver class.

here's example of had in old project of mine, had nsmutablearray held user generated data, , saved , loaded nskeyedarchiver (simplified show relevant code, , done on year ago when starting ios, might not best possible way of doing it):

- (bool) savedata {     bool success = no;      nsarray *pathlist = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, no);      nsstring *path = [[[pathlist objectatindex:0] stringbyappendingpathcomponent:@"data.txt"] stringbyexpandingtildeinpath];      success = [nskeyedarchiver archiverootobject:myarray tofile:path];     //note: myarray nsmutablearray, nsarray      return success; }   - (bool) loaddata {     bool success = no;      nsarray *pathlist = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, no);      nsstring *path = [[[pathlist objectatindex:0] stringbyappendingpathcomponent:@"data.txt"] stringbyexpandingtildeinpath];      if( (myarray = [nskeyedunarchiver unarchiveobjectwithfile:path]) )     {         [myarray retain];         success = yes;     }     else     {         myarray = [[nsmutablearray alloc] init];         success = no;     }      return success; } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -