我有一個檔案存儲在「Presidents.plist」文件中。它存在,我可以使用pathForResource
方法找到它。而且我確實使用initWithContentsOfFile
方法NSData
獲取數據來檢索數據。現在的問題是在這行代碼中。NSKeyedUnarchiver decodeObjectForKey返回null類
NSString *path = [[NSBundle mainBundle] pathForResource:@"Presidents"
ofType:@"plist"];
NSData *data;
NSKeyedUnarchiver *unarchiver;
data = [[NSData alloc] initWithContentsOfFile:path];
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
id presidents = [unarchiver decodeObjectForKey:@"Presidents"];
出於某種原因,它返回一個空類而不是我預期的NSArray類。任何人都可以告訴我發生這種情況的原因,我該如何解決這個困境?
我越來越喜歡這個類...
NSLog(@"presidents class = %@", NSStringFromClass([presidents class]));
花花公子改變「BIDPresident」的「總統」在Presidents.plist!你是一個花花公子嗎?我做了這個'NSMutableDictionary dict = [unarchiver decodeObjectForKey:@「Presidents」];'並註銷了它。輸出是'dict =(null)';另一方面,plist的內容是一個數組。但是它也返回null。 – jovhenni19 2012-01-13 07:43:10
我更新了問題..請看看它!謝謝! – jovhenni19 2012-01-13 09:51:10