我使用以下代码将plist显示到NSDictionary / NSMutableDictionary中,但是当我打印该变量时它返回null值?请帮帮我?
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *Path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Recent.plist"];
NSLog(@"%@",Path); //Path is correct
NSDictionary *d=[[NSDictionary alloc]initWithContentsOfFile:Path];
NSMutableDictionary *data = [[NSMutableDictionary alloc]initWithContentsOfFile:Path];
NSLog(@"%@",d);
答案 0 :(得分:0)
Buddy,您的代码是正确的,但请确保您的plist根是数组或字典
我认为它应该是你的情况下的数组
请尝试此代码,我只需将NSMutableDictionary更改为代码中的NSMutableArray
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *Path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Recent.plist"];
NSLog(@"%@",Path);
NSMutableArray *d = [[NSMutableArray alloc]initWithContentsOfFile:Path];
必须工作