无法从plist读取

问题描述:

我有一个plist顶级数组,然后是其中的一些项目。无法从plist读取

当我尝试以下方法

NSString *path = [[NSBundle mainBundle] bundlePath]; 
NSString *finalPath = [path stringByAppendingPathComponent:@"Spots.plist"]; 

spotsArray = [[NSMutableArray arrayWithContentsOfFile:finalPath] retain]; 

数组spotsArray是空的。

我已经尝试了一些东西,并成功地使用过plists。我不知道现在是什么问题。

什么引起的问题,我的plist看起来像这样plist

它不是顶层数组,它是一个带有一个名为'New Item'的单个字典的字典。

尝试NSMutableArray *mutableArray = [[[NSDictionary dictionaryWithContentsOfFile:finalPath] objectForKey:@"New Item"] mutableCopy] autorelease]

这应该意味着你的.plist文件不存在或无法读取。 尝试使用writeToFile在同一路径上创建文件来验证它是否有效。 (它也可以帮助你验证目录)

+0

'[一个NSBundle mainBundle]'是iOS装置不可写 – 2011-05-26 13:49:44