这个解码器只会解码采用 NSSecureCoding 的类 [英] This decoder will only decode classes that adopt NSSecureCoding
本文介绍了这个解码器只会解码采用 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屋!
查看全文