我可以从 OS X 上创建的存档中检索 iOS 应用程序中的 NSAttributedString 吗?
我有一个使用 NSKeyedArchiver 存储数据的 Mac 程序。我在 iOS 应用程序中使用相同的代码来尝试从文件中读取数据,但在尝试解码 NSAttributedString 的实例时它崩溃了。 NSAttributedString 的 iOS 和 OS X 版本是否兼容,即这是 iOS 中的错误吗?
如果没有,除了修改 Mac 应用程序之外我还能做些什么吗?出于兼容性原因,我宁愿不必这样做。
I have a Mac program that stores its data using NSKeyedArchiver. I'm using the same code in an iOS app to try to read in the data from the file, but it crashes when trying to decode an instance of NSAttributedString. Are the iOS and OS X versions of NSAttributedString compatible, i.e. is this a bug in iOS?
If not, is there anything I can do short of modifying the Mac app? I'd prefer not to have to do that, for compatibility reasons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是正确的,请参阅: http://lists.apple.com/ archives/cocoa-dev/2010/Aug/msg00479.html
NSFont 与 UIFont 等。
You are correct see: http://lists.apple.com/archives/cocoa-dev/2010/Aug/msg00479.html
NSFont vs UIFont etc.
因此,如果不深入文档,我对这个答案并没有信心,但是虽然
NSAttributedString
在 iOS 和 OS X 上看起来可能相同,但它的一些属性却并非如此。例如,NSString
添加的内容在 iOS (UIStringDrawing.h) 和 Mac OS 上都不同。这可能与 iOS 上的解码器遇到或期望数据位于不存在的存档中有关。你能粘贴你得到的日志吗?通常,如果键控归档器遇到错误,它会将问题记录到控制台。
So I'm not confident in this answer without going in depth into the documentation, but whilst
NSAttributedString
may look identical on both iOS and OS X, some of its properties are not. For example,NSString
has additions that differ both on iOS (UIStringDrawing.h) and Mac OS.It could be to do with the decoder on iOS encountering or expecting data to be in the archive that doesn't exist. Could you paste the logs you get? Normally if a keyed archiver encounters an error it will log the problem to the console.