0
votes

I am simply trying to retrieve one item from my restful service (confirmed working)

http://www.example.com/person/25

I need to somehow pass in the '25' part of the URL. I figure that I'm supposed to use RKRoute. The way to execute this in RestKit is to use the getObject: method of RKObjectManager.

Using RestKit 0.22 and I do not know how to call the getObject: method because it expects a full Person object, no? Even though I only need to pass in the string '25'.

The method in question is: [self getObject:personNSManagedObject path:nil parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) .....

I can't just say "Person *person = [[Person alloc] init] because Person is an NSManagedObject.

But when I do this:

NSManagedObjectContext *moc = self.managedObjectStore.mainQueueManagedObjectContext;
NSEntityDescription *person = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:moc];
Person *personNSManObj = [[Person alloc] initWithEntity:person insertIntoManagedObjectContext:nil];
personNSManObj.id = 3;

I get the following error:

Performing object mapping to temporary target objectID. Results may not be accessible without obtaining a permanent object ID. restkit.network:RKResponseMapperOperation.m:457 Failed to retrieve existing object with ID: 0x1664ac90

Any ideas?

1

1 Answers

1
votes

You should save the new object back to the persistent store. The data load and mapping is happening on a different thread but will try to map data back into the supplied object. Because the object is inserted but not saved it has a temporary managed object id which RestKit tries to convert into an object but can't. Saving will create a 'stub' object in the data store which RestKit will fully populate with the response data (assuming success).

An alternative approach is to supply a dictionary with the required key / value pair which will be inserted into the route. RestKit will then create the destination object for you.