krzysztofzablocki / PropertyMapper

Property mapping for Objective-C iOS apps.
http://merowing.info
MIT License
1.13k stars 81 forks source link

Asserts when receiving an NSArray instead of an NSDictionary #31

Closed alexito4 closed 10 years ago

alexito4 commented 10 years ago

Hi, I just updated to 2.5 and I'm really excited with the new features :)

Before the update I was using a modified version in which I surrounded some methods with a try/catch to avoid crashes in the testers devices because of the API changing constantly. Now I was thinking of use the new version to accomplish the same purpose, but I encountered a problem with an assertion.

JSON I expect:

{
    ...
    thing: 
        {
            a1 : "hello",
            ...
        },
    ...
}

Mapping:

    [KZPropertyMapper mapValuesFrom:properties 
                          toInstance:self
                       usingMapping:@{
                                  @"a1" : KZProperty(attribute1),
                                  }
     ];

JSON I'm reciving:

{
    ...
    thing: [],
    ...
}

This Asserts on line 252: AssertTrueOrReturn([key isKindOfClass:NSNumber.class]); inside the enumeration block.

The problem is natural. I'm giving an array to the mapper when it expects a dictionary. The crash is absolutely normal but with the new feature I was hoping that this won't happen anymore. If this is the desired behaviour there is no problem ;)

marekcirkos commented 10 years ago

Hi, thanks for checking out new version :). Can you try to compile in KZPM as Release? It should not fire assert and should not crash. I thought it might be useful to know when JSON is different then expected while you developing.

krzysztofzablocki commented 10 years ago

I agree with @marek, asserts are for catching problems in debug builds, if you strip asserts (as release does by default) this will not crash, it will just ignore that mapping.

alexito4 commented 10 years ago

Thanks guys! I had a misconfiguration in the test build. Sorry for that. Now works as expected. I really like how is working right now, this rocks! ;)