此解码器将仅解码采用NSSecureCoding的类 [英] This decoder will only decode classes that adopt NSSecureCoding

查看:154
本文介绍了此解码器将仅解码采用NSSecureCoding的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AppDelegate中,我称之为:

From AppDelegate i call this:

-(void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply{

    [SavedSearchesHack getAllMatches:^(MatchCollection * _Nonnull matchCollection) {
        reply(@{@"response" : matchCollection});
    }];
}

然后我在调用回复时收到此错误:

And then i get this error when calling the reply:

***由于未捕获的异常'NSInvalidUnarchiveOperationException'而终止应用程序,原因:'此解码器仅解码采用NSSecureCoding的类.类'Test.MatchCollection'不采用它.'

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

    public class func openParentApplication(userInfo: [NSObject : AnyObject], 
    reply: (([NSObject : AnyObject], NSError?) -> Void)?) -> Bool

只要我只返回"test"之类的对象而不是MatchCollection,我就不会出错.

As long as i return simply objects like "test" instead of a MatchCollection i get no error.

推荐答案

添加到 .h 文件

 // just the protocol

@interface PacketH: NSObject<NSSecureCoding>

添加 .m 文件

+ (BOOL)supportsSecureCoding {
   return YES;
}

这篇关于此解码器将仅解码采用NSSecureCoding的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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