dchohfi / KeyValueObjectMapping

Automatic KeyValue Object Mapping for Objective-C, parse JSON/plist/Dictionary automatically
http://dchohfi.com/
MIT License
600 stars 90 forks source link

New API: addMapper: #70

Closed modamoda closed 9 years ago

modamoda commented 9 years ago

Please refer to dchohfi#69 : Sugar API that supports addObjectMapping and addArrayMapper in single API

dchohfi commented 9 years ago

@modamoda hey man, sorry but I don't really like the idea :( I really think that types are important, especially for type checking and warnings at runtime.

modamoda commented 9 years ago

Thanks for your reply. :) I totally agree with you that types are important

But if you are worrying about type safety, it does check safety both runtime and compile time. The first parameter id<DCMapping> checks it at compile time. and isKindOfClass checks it at runtime.

https://github.com/modamoda/KeyValueObjectMapping/blob/9e1dad06233bde9a51de166e40be2018bf07b39a/KeyValueObjectMapping/DCParserConfiguration.m#L57-L67

- (void)addMapper: (id<DCMapping>)mapper {
    if ([mapper isKindOfClass:[DCArrayMapping class]]){
        [self addArrayMapper:mapper];
    } else if ([mapper isKindOfClass:[DCObjectMapping class]]){
        [self addObjectMapping:mapper];
    } else {
        @throw [NSException exceptionWithName:NSInternalInconsistencyException
                                       reason:[NSString stringWithFormat:@"unknown mapper class: %@", NSStringFromClass([mapper class])]
                                     userInfo:nil];
    }
}

If you find any problem that I missed, please let me know :smile:

dchohfi commented 9 years ago

@modamoda cool, accepted :) would you mind to create a new podspec for those new reviews? it's great to receive pullrequest from you, thx a lot.

dchohfi commented 9 years ago

@modamoda oh, I forgot. could you also add a unit test to cover the exception case? just to make sure everything is tested. thx

modamoda commented 9 years ago

Sure, why not? I'll work on it.