我试图将核心数据中的一系列习俗类别作为可变的属性加以节省,但在试图装上所节省的数据时却留下以下错误:
NSSecureUnarchiveFromData transformer> threw while decoding a value. ({
NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=4864 "value for key NS.objects was of unexpected class MyCustomClass
In the Core Data schema I have set the transformer to "NSSecureUnarchiveFromData" and the Custom Class to "NSArray" (since I want to save an array of "MyCustomClass")
MyCustomClass.h
@interface MyCustomClass : NSObject <NSSecureCoding>
@property (nonatomic, assign) NSString *identifier;
MyCustomClass.m
@implementation MyCustomClass
+ (BOOL)supportsSecureCoding {
return YES;
}
- (void)encodeWithCoder:(nonnull NSCoder *)coder {
[coder encodeObject:self.identifier forKey:@"Identifier"];
}
- (nullable instancetype)initWithCoder:(nonnull NSCoder *)coder {
if (self = [super init]) {
self.identifier = [coder decodeObjectOfClass:[NSString class] forKey:@"Identifier"];
}
return self;
}
我甚至试图将“MyCustomClass+CoreDataProperties”的财产申报改为NSArray<MyCustom 班级* ;但也有同样的错误。
我没有采取什么步骤,或者说错了?