开发者

Can't read from plist

开发者 https://www.devze.com 2023-03-08 18:27 出处:网络
I have a plist with an array at top level and then a number of items within it. When I try the following

I have a plist with an array at top level and then a number of items within it.

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. I dont know what the issue is now.

What could be causing the issue, my plist looks like this

Can't read from 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]


This should mean that your .plist file does not exist or not readable. Try to create the file with writeToFile at the same path to verify it works. (It can also help you to verify the directory)

0

精彩评论

暂无评论...
验证码 换一张
取 消