2014-10-17 48 views

回答

1

使用以下方式可以检测字典的根元素是通过客观-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"); 
} 
+0

阵列或不理想的情况下的代码还应该检查是否'messagesInfo'是' nil'以防万一这个URL没有引用一个有效的plist文件(或者一个不存在的文件)。 – rmaddy 2014-10-17 04:45:22