ios - How to add new Key to nested plist -
i have custom plist in app, want add together new key @ nested level.
how can add together ? programatically ?
here construction of plist file: : how accomplish ?
please help , in advance.
you can not edit files in app-bundle. have read in nsmutabledictionary
, alter , save documents folder.
/*--- bundle file ---*/ nsstring *path = [[nsbundle mainbundle] pathforresource:@"products" oftype:@"plist"]; nsmutabledictionary *rootdict = [[nsmutabledictionary alloc] initwithcontentsoffile:path]; /*--- set value key ---*/ [rootdict setvalue:@"newkeycontent" forkeypath:@"mobiles.brands.thenewkey"]; /*--- documents path ---*/ nsstring *documentsdirectory = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) lastobject]; nsstring *writablepath = [documentsdirectory stringbyappendingpathcomponent:@"products.plist"]; /*--- save file ---*/ [rootdict writetofile:writablepath atomically: yes];
after have open documents directory otherwise start clean slate.
/*--- documents file ---*/ nsstring *docpath = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) lastobject]; nsstring *path = [docpath stringbyappendingpathcomponent:@"products.plist"]; nsmutabledictionary *rootdict = [[nsmutabledictionary alloc] initwithcontentsoffile:path]; /*--- set value key ---*/ [rootdict setvalue:@"newkeycontent" forkeypath:@"mobiles.brands.thenewkey"]; /*--- bundle file ---*/ [rootdict writetofile:writablepath atomically: yes];
ios objective-c plist
No comments:
Post a Comment