Short story: Old app is Objective C. New app (with same bundle ID, so it's an upgrade) is Xamarin on iOS. Old app stored data using NSKeyedArchiver
. I need to get this data using the new Xamarin app.
My preference is to create a new C# class to use with KeyedArchiver to retrieve the data, but I don't seem to be able to find examples of how to create a C# class that would work correctly.
Old app has an interface in objective C with properties:
@interface MyInterfaceName : NSObject<NSCoding>
@property (nonatomic,copy)NSString* variable1;
@property (nonatomic,strong)NSMutableString* variable2;
@property (nonatomic,strong)NSDate* date;
@property (nonatomic,assign)BOOL truthy;
@property (nonatomic,assign)_MYENUM enumVar;
And encoder functionality:
-(void) encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:self.variable1 forKey:@"key1"];
[encoder encodeObject:self.variable2 forKey:@"key2"];
[encoder encodeObject:self.date forKey:@"key3"];
[encoder encodeObject:[NSNumber numberWithInteger:self.enumVar] forKey:@"key4"];
[encoder encodeObject:[NSNumber numberWithBool:self.truthy] forKey:@"key5"];
}
- (id)initWithCoder:(NSCoder *)decoder {
NSString* variable1 = [decoder decodeObjectForKey:@"key1"];
NSString* variable2 = [decoder decodeObjectForKey:@"key2"];
NSString* date = [decoder decodeObjectForKey:@"key3"];
BOOL truthy = [[decoder decodeObjectForKey:@"key5"]boolValue];
_MYENUM enumVar = [[decoder decodeObjectForKey:@"key4"]integerValue];
return [self initWithTitle:search keyWord:keyWord toUser:to fromUser:from fromDate:fromDate toDate:toDate hasAttachment:hasAttachment dateRangeType:dateRangeType];
}
How do I duplicate this in C# in a way that will allow NSKeyedArchiver to stop throwing Objective-C exception thrown. Name: NSInvalidUnarchiveOperationException Reason: *** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (MyInterfaceName) for key (NS.objects); the class may be defined in source code or a library that is not linked
and give me access to the data within the archive?