krzysztofzablocki / PropertyMapper

Property mapping for Objective-C iOS apps.

Home Page:http://merowing.info

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Asserts when receiving an NSArray instead of an NSDictionary

alexito4 opened this issue · comments

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 ;)

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.

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.

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! ;)