通过快速枚举从 PLIST 中获取数据

Fetching data from PLIST by Fast Enumeration

我正在使用 for in 循环从 plist 中获取数据。For in 循环是正确的,因为它是打印值。但是,突然,它显示以下 exception:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndexedSubscript:]: unrecognized selector sent to instance 0x97a14b0'.

代码:

   NSString *sss=[[NSBundle mainBundle]pathForResource:@"s" ofType:@"plist"];

    NSDictionary *dic=[[NSDictionary alloc]initWithContentsOfFile:sss];

    for(NSArray *arr in [dic allKeys])
    {

    NSLog(@"%@",arr); // Ii is printing value

    NSLog(@"%@",arr[0]); // It is showing exceptions
    }

Plist:

NSLog(@"%@",arr[0]); 有一些问题。我想打印数组 ab.

的第一个索引的值

此处 [dic allKeys] 将是 dic 中的键 NSString,如 "a"、"b" 等

所以对于你的 plist,代码应该是,

NSString *sss=[[NSBundle mainBundle]pathForResource:@"s" ofType:@"plist"];

NSDictionary *dic=[[NSDictionary alloc]initWithContentsOfFile:sss];

for(NSString *key in [dic allKeys])
{

     NSLog(@"%@",key); 
     NSArray *value = [dic objectForKey:key];
     NSLog(@"%@",value[0]); 
}