2
我想解除特定類型的對象數組,但initWithCoder:函數不會在對象的類中執行。相反,我給出的錯誤:initWithCoder:函數不從unarchiveObjectWithData調用:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SavedObject initWithCoder:]: unrecognized selector sent to instance 0x9e85f34'
現在,奇怪的是,在encodeWithCoder:叫,我能夠將數據寫入到磁盤就好了。然後當試圖讀取數據時,數據看起來與寫入磁盤的數據完全相同。
寫入磁盤:
// arrayOfObjectsToSave
NSData *arrayData = [NSKeyedArchiver archivedDataWithRootObject:arrayOfObjectsToSave];
// uses NSData writeToURL - Works fine!
[self writeToDisk:arrayData];
使用控制檯一個PO的命令,我可以確認arrayData看起來是沿着線:
<62706c69 73743030 ... 00000000 00000288>
讀取數據傳回:
// url passed through
NSData *readBack = [self readDataFromURL:dataURL];
NSArray *persisitedArray = [NSKeyedUnarchiver unarchiveObjectWithData:readBack]
readBack的數據爲:
<62706c69 73743030 ... 00000000 00000288>
但應用程序似乎崩潰了上面的錯誤unarchiveObjectWithData:行,但似乎甚至沒有在我的類上調用initWithCoder:。
而且,最這一切了...它正常工作在iOS 7
你說它適用於iOS 7.它不起作用? – rmaddy
似乎無法在iOS 6上運行。 – Taz