【问题标题】:Alternative for NSKeyedArchiver/ NSKeyedUnarchiver iOSNSKeyedArchiver/ NSKeyedUnarchiver iOS 的替代方案
【发布时间】:2016-05-13 10:07:49
【问题描述】:

我有一本字典,它在归档后写入文件 [NSKeyedArchiver archivedDataWithRootObject:dictionary] 。我获取文件内容并通过多点将存档数据传输到我的对等设备。然后,在我的对等设备中,我使用[NSKeyedUnarchiver unarchiveObjectWithData:data] 取消归档数据。但是,它在取消归档时返回 nil,尽管其中存在数据。

我怀疑文件中的内容很大。 NSkeyedArchiver/ NSKeyedUnarchiver 有什么替代品吗?

代码: 归档:

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

转让:

[NSData dataWithContentsOfFile:fileAtPath] ;

取消归档:

[NSKeyedUnarchiver unarchiveObjectWithData:data];

【问题讨论】:

  • 您是如何归档和取消归档的?编写你的代码

标签: ios objective-c nskeyedarchiver nskeyedunarchiver


【解决方案1】:

试着像下面这样写数据,

 [data writeToFile:filePath atomically:NO];

这里的data 表示[NSKeyedArchiver archivedDataWithRootObject:dictionary] 您的存档数据。

否则存档和未存档的方法都可以。

希望这会有所帮助:)

【讨论】:

  • dint 工作..同样的问题,解压缩时字典为零,否则出现异常“无法理解的存档”
猜你喜欢
  • 1970-01-01
  • 2012-05-10
  • 2019-12-10
  • 1970-01-01
  • 2013-05-08
  • 1970-01-01
  • 1970-01-01
  • 2019-01-05
  • 1970-01-01
相关资源
最近更新 更多