解析和 watchkit 扩展 [英] Parse and watchkit extension

查看:20
本文介绍了解析和 watchkit 扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WatchKit 构建一个应用程序,并想使用来自我在课堂上的 PFObjects 的数据填充表,但出现此错误:

I am building an app using WatchKit and would like to populate a Table with data from PFObjects I have in a class but I got this error:

由于未捕获的异常而终止应用'NSInvalidUnarchiveOperationException',原因:'这个解码器将只解码采用 NSSecureCoding 的类.PFObject"类确实如此不要采用它.'

Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'This decoder will only decode classes that adopt NSSecureCoding. Class 'PFObject' does not adopt it.'

遇到与这篇文章相同的问题

推荐答案

您是否考虑过为 PFObject 添加一个采用 NSSecureCoding 协议的 Swift 扩展?

Have you considered adding a Swift extension to PFObject that adopts the NSSecureCoding protocol?

我还没有尝试过此操作,但鉴于错误消息,期望此操作有效似乎是合理的.

I haven't tried this action but it seems reasonable to expect this to work given the error message.

推荐操作

为了符合NSSecureCoding:

In order to conform to NSSecureCoding:

一个不覆盖initWithCoder的对象:可以不做任何改变地符合NSSecureCoding(假设它是另一个符合的类的子类).

An object that does not override initWithCoder: can conform to NSSecureCoding without any changes (assuming that it is a subclass of another class that conforms).

覆盖 initWithCoder: 的对象必须使用 decodeObjectOfClass:forKey: 方法解码任何封闭的对象.例如:

An object that does override initWithCoder: must decode any enclosed objects using the decodeObjectOfClass:forKey: method. For example:

快速

let obj = decoder.decodeObjectOfClass(MyClass.self, forKey: "myKey")

此外,该类必须覆盖其 supportsSecureCoding 方法以返回 true.

In addition, the class must override its supportsSecureCoding method to return true.

如果使用 Objective-C,那么类别似乎是一个合适的解决方案.

If using Objective-C then a category seems like a suitable solution.

这篇关于解析和 watchkit 扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆