Solution file
-(Instancetype) Initwithcoder: (Nscoder *) Adecoder
{
if (self = [super init]) {
unsigned int count;
ivar* Ivars = Class_copyivarlist ([self class], &count);
for (int i = 0; i < count; i++) {
Ivar Ivar = ivars[i];
Const char* name = Ivar_getname (Ivar);
nsstring* strName = [NSString stringwithutf8string:name];
ID value = [adecoder decodeobjectforkey:strname];
[Self setvalue:value forkey:strname];
}
Free (ivars);
}
return self;
}
Archive
-(void) Encodewithcoder: (Nscoder *) Acoder
{
unsigned int count;
Ivar *ivars = Class_copyivarlist ([self class], &count);
for (int i = 0; i < count; i++) {
Ivar Ivar = ivars[i];
Const char* name = Ivar_getname (Ivar);
nsstring* strName = [NSString stringwithutf8string:name];
ID value = [self valueforkey:strname];
[Acoder Encodeobject:value Forkey:strname];
}
Free (ivars);
}
Header files must be imported
#import <objc/runtime.h>
iOS Files and Archives