我正在尝试将以下plist加载到NSArray中:
以下是我用来加载数据的代码:
// Load the data from the plist file
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"MyData" ofType:@"plist"];
NSArray *myArray = [[NSArray alloc] initWithContentsOfFile:filepath];
但是当我在加载数据后放置一个断点时,我注意到该数组是空的。请有人帮我理解出了什么问题吗?
答案 0 :(得分:2)
您的plist文件包含一个包含数组的字典。试试这个
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:filePath];
NSArray *array = [[NSArray alloc]initWithArray:[dict objectForKey:@"Root"]];
答案 1 :(得分:1)
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"name.plist"];
NSArray *plistData = [NSArray arrayWithContentsOfFile:finalPath];