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

查看:111
本文介绍了解析和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.'

此帖子

推荐答案

您是否考虑过向采用NSSecureCoding协议的PFObject添加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:的对象必须使用encodeObjectOfClass:forKey:方法对所有封闭的对象进行解码.例如:

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

SWIFT

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天全站免登陆