开发者

Loading Array From .Plist

开发者 https://www.devze.com 2023-03-26 19:04 出处:网络
I\'m trying to load my array from an array in my .Plist but its not working. The plist looks like this:

I'm trying to load my array from an array in my .Plist but its not working.

The plist looks like this:

Loading Array From .Plist

This is the code I'm using:

NSString *path = [[NSBundle mainBundle]pathF开发者_JS百科orResource:@"DiseasePropertyList" ofType:@"plist"];
NSMutableArray *rootLevel = [[NSMutableArray alloc]initWithContentsOfFile:path];
self.myArray = rootLevel;
[rootLevel release];


Try this. Please change file name. It works fine.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *recentFilePath = [documentsDirectory stringByAppendingPathComponent:@"recent.plist"];
NSArray *history = [NSArray arrayWithContentsOfFile:recentFilePath];


Your plist is actually a dictionary. The array is the object of that dictionary for key "Array". You can make the plist into an array in Xcode 4 by selecting "Array" and cutting (CMD-x), and then pasting into the empty plist (CMD v).


NSString *pathStr = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [settingsBundlePath stringByAppendingPathComponent:@"yourproject.plist"]; 
NSDictionary *settingsDict = [NSDictionary dictionaryWithContentsOfFile:finalPath];

and just check the description of settingsDict. Hope this help you.


If your plist file is in your application bundle, the easiest is this:

NSArray *myArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"filename_without_extension" ofType:@"plist"]];


Use this method it worked fine for me.

NSArray *country= [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"CountryList" ofType:@"plist"]];
0

精彩评论

暂无评论...
验证码 换一张
取 消