krzysztofzablocki / PropertyMapper

Property mapping for Objective-C iOS apps.

Home Page:http://merowing.info

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Relationship mapping

ngoccuong291 opened this issue · comments

To whom it may concern

I have been using a couple of data mapping libraries and this one seems to be very light weight and easy to use. However one of the thing I would love to have is relationship mapping. Like one-one, one-many relationship

I.e:
With this dictionary
@{
@"videoURL" : @"http://test.com/video.mp4",
@"name" : @"Some Cool Video",
@"videoType" : [NSNull null],
@"sub_object" : @{
@"title" : @616,
@"arbitraryData" : @"data"
}
}

Can I map the sub_object to a class that I already have

@interface MyClass: NSObject

@Property NSString title;
@Property NSString arbitraryData

@EnD

Kind regards
Leon

If an object owns subobject what I normally do is:

  @"subobject" : @"@Selector(subobjectFromDictionary:, mySubobject)",

If you'd like to map to existing object, you should be able to do:

@"sub_object" : @{
@"title" : @"subObject.title", 
@"arbitraryData" : @"subObject.arbitraryData"
 }

We could think about potential expansion to add extra functionality, do you have any proposal?

It looks good for me. I'm thinking about passing a block to parse the object but not quite sure if it's possible.
Anyway, your solution looks good to me.

Just one more thing, is there any way we can make it less fragile? Like when I change the property name of MyClass, the mapping will change with it and we can detect it at compile time without running unit test again.

Thanks

That would be tricky, you could try using NSStringFromSelector to get property name, if it doesn't recognise selector it should generate warning and thus not compile (warnings as errors 👍).
But I think it would complicate the readability too much, any other suggestions ?

:( Sorry, so far, I don't have any other ideas. Thanks, anyway