2010-02-28 34 views
1

我目前正试图从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的问题。

问题在哪里?

谢谢(:

+0

您需要逐步通过这个代码,并找出它不工作。你的任何方法都可能会失败,返回null,然后级联,直到最后赋值为NULL。这就是gdb的作用。 – 2010-02-28 22:06:51

回答

2

你忘了的Alloc的NSDictionary中和的NSArray,所以数组和字典不能保存的值

+0

Eh?提问者是从文件创建NSDictionary,所以没有必要分配一个,并从字典中获取数组。有几个原因可能会失败,但不发送'alloc'消息不是其中之一。 – 2010-08-31 12:56:46