简体   繁体   English

无法从 plist 中读取

[英]Can't read from plist

I have a plist with an array at top level and then a number of items within it.我有一个 plist,其中包含一个数组,然后是其中的一些项目。

When I try the following当我尝试以下

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

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

the array spotsArray is empty.数组点数组为空。

I have tried a number of things and have used plists successfully before.我已经尝试了很多东西,并且之前成功地使用过 plist。 I dont know what the issue is now.我不知道现在是什么问题。

What could be causing the issue, my plist looks like this可能是什么导致了这个问题,我的 plist 看起来像这样列表

It's not an array at the top level it's a dictionary with a single item called 'New Item'.它不是顶层的数组,它是一个字典,其中包含一个名为“新项目”的项目。

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

This should mean that your.plist file does not exist or not readable.这应该意味着 your.plist 文件不存在或不可读。 Try to create the file with writeToFile at the same path to verify it works.尝试使用 writeToFile 在同一路径创建文件以验证它是否有效。 (It can also help you to verify the directory) (它还可以帮助您验证目录)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM