我目前正试图从plist中获取数据。未能从plist读取数组数据 - (null)弹出
基本上,它看起来像这样:
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] stringtest(null)
由于objectAtIndex:2返回相同,所以它不是arcrandom的问题。
问题在哪里?
谢谢(:
您需要逐步通过这个代码,并找出它不工作。你的任何方法都可能会失败,返回null,然后级联,直到最后赋值为NULL。这就是gdb的作用。 – 2010-02-28 22:06:51