Parse and watchkit extension

*爱你&永不变心* 提交于 2020-01-14 08:48:20

问题


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:

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

Having the same problem as this post


回答1:


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.

Recommended Action

In order to conform to 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).

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")

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

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




回答2:


In the watch's interface controller simply set call Parse's credentials again:

[Parse setApplicationId:@"APPID" clientKey:@"CLIENTKEY"];

and create a new PFQuery just for the watch. It doesn't matter if communication fails or not.



来源:https://stackoverflow.com/questions/30366934/parse-and-watchkit-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!