3

Log:

2014-04-09 15:03:10.196 App[49808:60b] request <NSMutableURLRequest: 0xd091170> { URL: http://www.domain.com/meetups?lastrequest=2014-04-09T15%3A03%3A10Z }
2014-04-09 15:03:10.214 App[49808:60b] I restkit.network:RKObjectRequestOperation.m:180 GET 'http://www.domain.com/meetups?lastrequest=2014-04-09T15%3A03%3A10Z'
2014-04-09 15:03:10.300 App[49808:632f] D restkit.object_mapping:RKMapperOperation.m:377 Executing mapping operation for representation: {
    meetups =     (
                {
            activities =             (
                                {
                    activityId = 37;
                    activityType = "<null>";
                    customData = "<null>";
                    locationAddress = "k2-LocationAddress";
                    locationName = "k2-LocationName";
                    startTime = "0000-00-00 00:00:00";
                },
                                {
                    activityId = 38;
                    activityType = "<null>";
                    customData = "<null>";
                    locationAddress = "k-LocationAddress";
                    locationName = "k-LocationName";
                    startTime = "0000-00-00 00:00:00";
                }
            );
            comment = comment;
            gettingBack = "gettingBack Test";
            gettingThere = "gettingBack Test";
            meetingType = 1;
            meetupId = 65;
            modified = "2014-04-09T20:59:29.000Z";
            ownerId = Joe;
            recipientId = "<null>";
        }
    );
}
 and targetObject: (null)
2014-04-09 15:03:10.301 App[49808:632f] D restkit.object_mapping:RKMapperOperation.m:403 Finished performing object mapping. Results: (null)
2014-04-09 15:03:10.302 App[49808:21f] E restkit.network:RKObjectRequestOperation.m:243 GET 'http://www.domain.com/meetups?lastrequest=2014-04-09T15%3A03%3A10Z' (200 OK / 0 objects) [request=0.0849s mapping=0.0000s total=0.1043s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0xd0b5a40 {NSErrorFailingURLStringKey=http://www.domain.com/meetups?lastrequest=2014-04-09T15%3A03%3A10Z, NSLocalizedFailureReason=A 200 response was loaded from the URL 'http://www.domain.com/meetups?lastrequest=2014-04-09T15%3A03%3A10Z', which failed to match all (0) response descriptors:, NSLocalizedDescription=No response descriptors match the response loaded., keyPath=null, NSErrorFailingURLKey=http://www.domain.com/meetups?lastrequest=2014-04-09T15%3A03%3A10Z, NSUnderlyingError=0xd08a190 "No mappable object representations were found at the key paths searched."}

Code:

@property (strong, nonatomic) RKObjectManager *objectManager;
....

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.objectManager = [self getObjectManager];

self.objectManager.managedObjectStore = [appDelegate setupCoreDataWithRESTKit];

[RKObjectManager sharedManager].requestSerializationMIMEType = RKMIMETypeJSON;

RKEntityMapping *invitationMapping = [RKEntityMapping mappingForEntityForName:@"Invite" inManagedObjectStore:self.objectManager.managedObjectStore];
[invitationMapping addAttributeMappingsFromDictionary:@{
                                                        @"recipientId" : @"recipientId",
                                                        @"meetingType" : @"meetingType",
                                                        @"startDate" : @"startDate",
                                                        @"gettingThere" : @"gettingThere",
                                                        @"gettingBack" : @"gettingBack",
                                                        @"comment" : @"comment"
                                                        }];
invitationMapping.identificationAttributes = @[@"meetupId"];

RKEntityMapping *activityMapping = [RKEntityMapping mappingForEntityForName:@"Activity" inManagedObjectStore:self.objectManager.managedObjectStore];
[activityMapping addAttributeMappingsFromDictionary:@{
                                                      @"locationName" : @"locationName",
                                                      @"locationAddress" : @"locationAddress",
                                                      @"startTime" : @"startTime",
                                                      @"customData" : @"customData"
                                                      }];
activityMapping.identificationAttributes = @[@"activityId"];
NSIndexSet *statusCodeSet = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);

[invitationMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"activities" toKeyPath:@"activities" withMapping:activityMapping]];


RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:invitationMapping
                                                                                        method:RKRequestMethodGET
                                                                                   pathPattern:@"/meetups"
                                                                                       keyPath:@"meetups" statusCodes:statusCodeSet];


NSMutableURLRequest *request = [self.objectManager.HTTPClient requestWithMethod:@"GET"
                                                                           path:@"/meetups"
                                                                     parameters:@{@"lastrequest": dateString

                                                                                  }];

 [self.objectManager.HTTPClient  registerHTTPOperationClass:[AFHTTPRequestOperation class]];

RKManagedObjectRequestOperation *operation = [[RKManagedObjectRequestOperation alloc]initWithRequest:request responseDescriptors:@[responseDescriptor]];

operation = [self.objectManager managedObjectRequestOperationWithRequest:request managedObjectContext:self.objectManager.managedObjectStore.mainQueueManagedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    NSArray *array = mappingResult.array;
    NSLog(@"array %@", array);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {

}];

[operation start];
}

Invite has to-many relationship with Activity called activities.

Why am I getting: "No mappable object representations were found at the key paths searched." ?

user1107173
  • 10,334
  • 16
  • 72
  • 117
  • Turn on trace logging. Set the path pattern on the response descriptor to nil (just when using `RKManagedObjectRequestOperation` directly). Is there a reason you aren't using the object manager directly? – Wain Apr 10 '14 at 07:22
  • Thanks. I did turn the trace logging in AppDelegate: RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace); When I set the path pattern to nil, I get the same error. I'm using RKManagedObjectRequestOperation, b/c that's what seems to be suggested based on other SO questions. Should I be using Object Manager instead? – user1107173 Apr 10 '14 at 17:09
  • Personally I 99% use `RKObjectManager` and 1% specific operations directly. What is the bast URL you're using? – Wain Apr 10 '14 at 17:11
  • NSURL *baseURL = [NSURL URLWithString:@"http://rest.domain.com"]; Do you need the real domain? – user1107173 Apr 10 '14 at 17:13
  • 1
    I was wondering if it has a `/` at the end, but that shouldn't really matter when using `RKManagedObjectRequestOperation` directly. I can't see any particular issue. Can you post the trace log somewhere? – Wain Apr 10 '14 at 17:17
  • I post it up under Log in the question. I'm getting the same exact response with nil in path pattern. – user1107173 Apr 10 '14 at 17:20
  • I was expecting the trace log to say which response descriptors it tried and failed to match – Wain Apr 10 '14 at 17:23
  • I do get a trace log for the mapping that works for other API calls. However, the log above is all I get for this. Should I switch to ObjectManager? – user1107173 Apr 10 '14 at 17:33
  • I think I see the problem, 1 minute.... – Wain Apr 10 '14 at 17:44

1 Answers1

1

This is the correct way to create the operation:

RKManagedObjectRequestOperation *operation = [[RKManagedObjectRequestOperation alloc]initWithRequest:request responseDescriptors:@[responseDescriptor]];

but then you replace that one with another created with:

operation = [self.objectManager managedObjectRequestOperationWithRequest:request managedObjectContext:self.objectManager.managedObjectStore.mainQueueManagedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {

which uses the object manager proper. This issue is that you haven't given the response descriptor to the object manager, you only gave it to the operation that was just destroyed (because you replaced it).

So, use the first operation you created and set the success and failure blocks on it by calling setCompletionBlockWithSuccess:failure:.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • You need to set `managedObjectContext` on the operation before you execute it (another benefit of using the object manager is that this is done for you) – Wain Apr 10 '14 at 19:07
  • 1
    operation.managedObjectContext = self.objectManager.managedObjectStore.mainQueueManagedObjectContext; I think this line above did it! – user1107173 Apr 10 '14 at 19:09
  • Last question: I see the objects coming back and being mapped. How are they persisted in Core Data? – user1107173 Apr 10 '14 at 19:20
  • 1
    Just a little question then :-) RestKit uses your `responseDescriptor` to know what entity type to create and how to map the incoming data into those new instances. After the mapping is complete it saves the MOC. That's why you need to set the `managedObjectContext` of the operation. So it can create and save the response. – Wain Apr 10 '14 at 19:23
  • Since you are the SO RESTtKit guru, can I ask what are you doing with RESTKit for Swift? Are you using something else (please share), or sticking to RESTKit? – user1107173 Nov 05 '14 at 05:14
  • 1
    I don't use Swift currently as it isn't mature enough for any of my clients to move to it yet. There isn't currently (that I'm aware of) any plan to migrate RestKit to Swift. I'm not planning a move away from RestKit just yet – Wain Nov 05 '14 at 13:05
  • Have you seen this error before: http://stackoverflow.com/questions/27350713/restkit-nsinternalinconsistencyexception-reason-unable-to-perform-mapping – user1107173 Dec 08 '14 at 02:58