Objective-C Object Mapping
I think basically any Objective-C developer who has spent some time on the platform has written a half dozen different ways to turn a dictionary into a model object:
SomeModelObject *model = [[SomeModelObject alloc] init];
model.someProperty = [someDictionary objectForKey:@"someProperty"];
//etc
or a little better
@implementation SomeModelObject
- (id)initWithDictionary:(NSDictionary *)dictionary
{
self = [super init];
if (self)
{
self.someProperty = [dictionary objectForKey:@"someProperty"];
}
return self;
}
and then there’s transformations, like turning a string into a date, etc.
While I was at Bottle Rocket, we decided to formalize this process and write something that would make it easy and consistent to turn dictionaries into model objects and back into dictionaries.
When I left Bottle Rocket, I had gotten so used to having this tool at my disposal I decided, with BR blessing, to build my own.
ESObjectMap is my 2.0 take on this problem:
- Easy configuration from a dictionary for native model objects and core data objects
- Mismatched field name mapping
- Built in basic data transforms for common data types and an easy path to build custom transforms
- Mapping of native model objects back into dictionaries
Couple of non-feature side notes:
- Written for ARC
- While it was built with JSON in mind, this is really just about getting from dictionaries to objects and back
- Uses my property introspection logic, so you have lots of meta data to work with when performing mappings and transforms.
Check out the project, let me know what you think. I’m pretty happy with where it is now, but there’s always room for improvement.