2016-05-13 65 views
0

我有一個字典在歸檔之後寫入文件[NSKeyedArchiver archivedDataWithRootObject:dictionary]。我獲取文件內容並通過多路徑傳輸存檔數據到我的對等設備。然後,在我的對等設備中,我使用[NSKeyedUnarchiver unarchiveObjectWithData:data]將數據解除歸檔。但是,雖然有數據存在,但它在解除它的同時返回零。NSKeyedArchiver/NSKeyedUnarchiver的替代方案iOS

我懷疑文件中的內容很大。有沒有其他替代品NSkeyedArchiver/NSKeyedUnarchiver

代碼: 歸檔:

[[NSKeyedArchiver archivedDataWithRootObject:dictionary] writeToFile:fileAtPath options:NSDataWritingAtomic error:&error]; 

轉移:

[NSData dataWithContentsOfFile:fileAtPath] ; 

解壓:

[NSKeyedUnarchiver unarchiveObjectWithData:data]; 
+0

你是如何歸檔和取消歸檔?寫你的代碼 – Lion

回答

0

嘗試寫像下面數據,

[data writeToFile:filePath atomically:NO]; 

這裏data意味着[NSKeyedArchiver archivedDataWithRootObject:dictionary]您的存檔數據。

否則存檔和未存檔的方法是好的。

希望這會有所幫助:)

+0

dint work..same issue,dictionary is nil while unarchiving or I get exception'incompresesible archive' – Jeyanthu