我有一个扩展的自定义类NSString
。我正在尝试使用NSKeyedArchiver
. 该类覆盖...Coder
方法:
- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
data = [[aDecoder decodeObjectForKey:@"data"] copy];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[super encodeWithCoder:aCoder];
[aCoder encodeObject:self.data forKey:@"data"];
}
但是当我尝试实际运行归档/取消归档时:
MyClass *object = [[MyClass alloc] init];
[pboard setData:[NSKeyedArchiver archivedDataWithRootObject:object] forType:SACP_WRAPPER_DRAG_TYPE];
NSLog(@"Wrote data for class %@", [object class]);
...
id item = [NSKeyedUnarchiver unarchiveObjectWithData:[[info draggingPasteboard] dataForType:SACP_WRAPPER_DRAG_TYPE]];
NSLog(@"Read data for class %@", [item class]);
输出不是我所期望的:
2011-10-15 18:56:22.898 MyApp[7402:707] Wrote data for class ASCIIString
2011-10-15 18:56:23.345 MyApp[7402:707] Read data for class __NSCFString