无法从plist读取

问题描述

| 我有一个在顶层具有数组的plist,然后在其中包含许多项。 当我尝试以下
Nsstring *path = [[NSBundle mainBundle] bundlePath];
Nsstring *finalPath = [path stringByAppendingPathComponent:@\"Spots.plist\"];

spotsArray = [[NSMutableArray arrayWithContentsOfFile:finalPath] retain];
数组spotArray为空。 我已经尝试了很多方法,并且之前已经成功使用了plists。我不知道现在是什么问题。 是什么引起了问题,我的plist看起来像这样     

解决方法

它不是顶级数组,而是一本字典,其中只有一个名为“'New Item \'”的项。 试试
NSMutableArray *mutableArray = [[[NSDictionary dictionaryWithContentsOfFile:finalPath] objectForKey:@\"New Item\"] mutableCopy] autorelease]
    ,这意味着您的.plist文件不存在或不可读。 尝试在同一路径下使用writeToFile创建文件以验证其是否有效。 (它也可以帮助您验证目录)