0
如何检查plist的根项目是数组还是字典? 感谢您的帮助plist文件中的根项目类型?
如何检查plist的根项目是数组还是字典? 感谢您的帮助plist文件中的根项目类型?
使用以下方式可以检测字典的根元素是通过客观-C
NSString *thePath = [[NSBundle mainBundle] pathForResource:@"YourCustom" ofType:@"plist"];
NSURL *theUrl = [NSURL fileURLWithPath:thePath];
id messagesInfo = [[NSDictionary dictionary] initWithContentsOfURL:theUrl];
if([messagesInfo isKindOfClass:NSDictionary]){
NSLog(@"DictionaryFound");
}
else{
NSLog(@"Array Found");
}
阵列或不理想的情况下的代码还应该检查是否'messagesInfo'是' nil'以防万一这个URL没有引用一个有效的plist文件(或者一个不存在的文件)。 – rmaddy 2014-10-17 04:45:22