我目前正試圖從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