ios - Why can't I retrieve my plist file? -
i have plist file created of strings; looks this:
this code i'm using create path file:
nserror *error; nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); // create list of paths nsstring *documentsdirectory = [paths objectatindex:0]; // path documents directory list nsstring *path = [documentsdirectory stringbyappendingpathcomponent:@"nailservices.plist"]; // create full file path nsfilemanager *filemanager = [nsfilemanager defaultmanager]; if (![filemanager fileexistsatpath: path]) { // check if file exists // path plist created before in bundle directory (by xcode) nsstring *bundle = [[nsbundle mainbundle] pathforresource: @"nailservices" oftype: @"plist"]; [filemanager copyitematpath:bundle topath: path error:&error]; // copy plist documents directory }
this code i'm using examine data (to make sure working)... i'm getting (null) nslog statement)
//load dictionary wood name cross refference values image name nsstring *plistdatapath = [[nsbundle mainbundle] pathforresource:@"nailservices" oftype:@"plist"]; nsdictionary *nailservicesdictionary = [[nsdictionary alloc] initwithcontentsoffile:plistdatapath]; nslog(@"\nnailservicesdict: %@", nailservicesdictionary);
this first attempt @ creating/using "strings" plist file; have read find on google , without finding example of plain ol' strings file. else have able plist data?
as commenter posted, plist files can either have nsarray
or nsdictionary
root. example plist has nsarray
root, you'll want alloc
, init
nsarray
, not nsdictionary
. if plist stored in app bundle when build app in xcode , don't need modify @ runtime, it's unnecessary copy nsdocumentsdirectory
. also, i'd recommend using [paths lastobject];
rather [paths objectatindex:0];
, can throw exception if paths
array empty.
Comments
Post a Comment