In a side project I needed a way to have some kind of proxy object, where all properties, which are defined as @dynamic, where handled by generic getters and setters. I build a small example project to share this solution. So if you need something similar, just copy and paste the snippets you need.
With this you can define your properties as usual in the interface …
@interface DPTestObject : DPObject @property (nonatomic, readwrite) NSString *name; @end
… and mark them as dynamic in the implementation.
@implementation DPTestObject @dynamic name; @end
Then, setting a property results into a populated dictionary:
DPTestObject *object = [[DPTestObject alloc] init];
object.name = @"Peter";
NSLog(@"values: %@", object.values);
>>> @{@"name": @"Peter"}
