无法解码密钥(NS.object.0)的Employee类的对象;该类可以在源代码或未链接的库中定义 [英] Cannot decode object of class Employee for key (NS.object.0); the class may be defined in source code or a library that is not linked

查看:76
本文介绍了无法解码密钥(NS.object.0)的Employee类的对象;该类可以在源代码或未链接的库中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过序列化员工"对象iPhone的数组到Apple Watch:

Im trying to pass an array of 'Employee' objects iPhone to Apple Watch by serializing the array :

NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:employees];

并将其反序列化为观看"端:

and unserializing it as on the Watch side:

NSMutableArray *employees = [NSKeyedUnarchiver unarchiveObjectWithData:encodedObject];

这是员工"类:

@interface Employee : NSManagedObject
@property (nonatomic, retain) NSNumber * employeeID;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * age;
@property (nonatomic, retain) NSString * address;
@property (nonatomic, retain) NSString * designation;
@property (nonatomic, retain) NSString * teamName;
@property (nonatomic, retain) NSString * gender;
@property (nonatomic, retain) NSNumber * dateOfJoining;
@end

我必须在手表方面进行任何更改以解决此错误吗?

Do I have to do any changes on the Watch side to fix this error?

推荐答案

所以我只是遇到了完全相同的问题,答案很简单,但自己很难找到.

so I just had that exact same problem and the answer is simple but a little hard to find by oneself.

您只需使用:

  • NSKeyedArchiver.setClassName("Employee", for: Employee.self)
    序列化之前
  • NSKeyedUnarchiver.setClass(Employee.self, forClassName: "Employee")
    反序列化之前
  • NSKeyedArchiver.setClassName("Employee", for: Employee.self)
    before serializing
  • NSKeyedUnarchiver.setClass(Employee.self, forClassName: "Employee")
    before deserializing

在任何需要的地方.

就像iOS扩展一样,类名以扩展名作为前缀.

Looks like iOS extensions prefix the class name with the extension's name.

这篇关于无法解码密钥(NS.object.0)的Employee类的对象;该类可以在源代码或未链接的库中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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