遇到了一些问题。我有一个.plist文件,其中包含下一个数据从.plist文件中读取
所以我不明白,我如何需要读取第一个数组,比在数组读取字典。或者,也许需要重写文件,并更改根键来输入字典,读这样的:
NSString *errorDesc = nil;
NSPropertyListFormat format;
NSString *plistPath;
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
plistPath = [rootPath stringByAppendingPathComponent:@"Data.plist"];
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
plistPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
}
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
propertyListFromData:plistXML
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&errorDesc];
if (!temp) {
NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
}
self.personName = [temp objectForKey:@"Name"];
self.phoneNumbers = [NSMutableArray arrayWithArray:[temp objectForKey:@"Phones"]];
除本扔出来的代码加载从Documents文件夹(如果存在)。 – rmaddy
它实际上并没有回答这个问题。问题是关于从数组中获取所需的数据。 – rmaddy
'objectAtIndex:'是一个旧的语法,有一些更新的 –