I have a custom class that extends NSString
. I'm attempting to serialize it (for drag/drop) using an NSKeyedArchiver
. The class overrides the ...Coder
methods:
- (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"];
}
But when I try to actually run through the archiving/unarchiving:
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]);
The output is not what I am expecting:
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