无法从 plist 读取数组数据 - (null) 被弹出
我目前正在尝试从 plist 中获取数据。
它基本上看起来像这样:
plist called 'woerter'
-> Root key of type Dictionary
-> woerter key of type Array
-> various Items of type String with string Values
当我现在尝试从中读取随机字符串时,我只得到一个(空)表达式
NSString * path = [[NSBundle mainBundle] bundlePath];
NSString * finalPath = [path stringByAppendingPathComponent:@"woerter.plist"];
NSDictionary * plistData = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];
NSArray * array = [plistData valueForKey:@"woerter"];
NSString * string = [array objectAtIndex:arc4random() %110];
NSLog(@"stringtest %@", string);
但我得到的是
2010-02-28 23:01:58.911 TypeFast[5606:a0f] 字符串测试(空)
这也不是 arcrandom 的问题,因为 objectAtIndex:2 返回相同的值。
问题出在哪里?
谢谢 (:
I am currently trying to get data out of a plist.
It basically looks like that:
plist called 'woerter'
-> Root key of type Dictionary
-> woerter key of type Array
-> various Items of type String with string Values
When I now try to read a random string from it, I only get a (null) expression
NSString * path = [[NSBundle mainBundle] bundlePath];
NSString * finalPath = [path stringByAppendingPathComponent:@"woerter.plist"];
NSDictionary * plistData = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];
NSArray * array = [plistData valueForKey:@"woerter"];
NSString * string = [array objectAtIndex:arc4random() %110];
NSLog(@"stringtest %@", string);
But all i get is
2010-02-28 23:01:58.911
TypeFast[5606:a0f] stringtest (null)
It is not a problem with arcrandom either since objectAtIndex:2 returns the same.
Where is the problem?
Thank you (:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您忘记分配 NSDictionary 和 NSArray,因此数组和字典无法保存值。
You forgot to alloc the NSDictionary and the NSArray, so the array and dictionary can not save the values.