ios - Edit Programmatically plist in the App bundle at development time -


i have created plist on xcode have few values can't insert manually. want add values programmatically @ development time. seems can read plist can not save plist on app bundle, makes sense @ runtime.. when distribute app want have plist file that's why not saving on documents or cache. how can achieve want?

from http://www.karelia.com/cocoa_legacy/foundation_categories/nsfilemanager__get_.m (pasted below) can build path within user's personal library -(nsstring *) pathfromuserlibrarypath:(nsstring *)insubpath method found there.

for example, nsstring *editedplist = [self pathfromuserlibrarypath:@"my.plist"]; gets name of modified plist within user's library (even if plist doesn't exist yet).

how read/write according kind of plist have, read dictionary with:

nsmutabledictionary *theplist= [[nsmutabledictionary alloc] initwithcontentsoffile:editedplist ]; 

if unable read, detected by, example [theplist count] == 0, instead call same initwithcontentsoffile: initializer path template within bundle, write plist out editedplist path appears in user directory.


here utility method referenced above:

/*     nsfilemanager: path within user's library directory     original source: <http://cocoa.karelia.com/foundation_categories/nsfilemanager__get_.m>     (see copyright notice @ <http://cocoa.karelia.com>) */  /*" return path in user library path of given sub-path.  in other words, if given insubpath "foo", path returned /users/myuser/library/foo "*/ -  (nsstring *) pathfromuserlibrarypath:(nsstring *)insubpath {     nsarray *domains = nssearchpathfordirectoriesindomains(nslibrarydirectory,nsuserdomainmask,yes);     nsstring *basedir= [domains objectatindex:0];     nsstring *result = [basedir stringbyappendingpathcomponent:insubpath];     return result; } 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -