Search code examples
iosmappingrestkit

Restkit : getting mappingResult with "<null>" in all requests


After executing a Restkit Request with "nil" keyPath which works fine, i get its response :

"<null>" = "<EstablishmentReservationsMapping: 0x7fc42d1140f0>"

But i'm still getting it In all the mappingResults of the next requests, like this :

"<null>" = "<EstablishmentReservationsMapping: 0x7fc42d1140f0>";
"my_establishments" =     (
        "<Establishment: 0x7fc42f89ae10>",
        "<Establishment: 0x7fc42f89b220>",
        "<Establishment: 0x7fc42f89b8f0>",
        "<Establishment: 0x7fc42f90bd10>",
        "<Establishment: 0x7fc42f990d60>",
        "<Establishment: 0x7fc42f93a650>",
        "<Establishment: 0x7fc42f9e6bb0>",
        "<Establishment: 0x7fc42fe9a0a0>",
        "<Establishment: 0x7fc42f9dcbc0>"
    );

I want to get just :

"my_establishments" =     (
    "<Establishment: 0x7fc42f89ae10>",
    "<Establishment: 0x7fc42f89b220>",
    "<Establishment: 0x7fc42f89b8f0>",
    "<Establishment: 0x7fc42f90bd10>",
    "<Establishment: 0x7fc42f990d60>",
    "<Establishment: 0x7fc42f93a650>",
    "<Establishment: 0x7fc42f9e6bb0>",
    "<Establishment: 0x7fc42fe9a0a0>",
    "<Establishment: 0x7fc42f9dcbc0>"
);

And this is the response responseDescriptor for the second request :

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:establishmentMapping method:RKRequestMethodGET pathPattern:nil keyPath:@"my_establishments" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

[_objectManager addResponseDescriptor:responseDescriptor];

Solution

  • The problem is pathPattern:nil because it means that all of the response descriptors will always be considered for every response. This results in empty objects being created in many cases.

    To fix, add path patterns to each response descriptor so RestKit can tell which one(s) it should use.