0
votes

I am developing a todo list app using RestKit on iOS, i have added a fetch results block for deletion of orphaned objects from official class reference from this link (http://restkit.org/api/latest/Classes/RKManagedObjectRequestOperation.html)

Now the documentation says whenever any RKManagedObjectRequestOperations execute, the fetch result block will check for orphaned objects and delete the objects automatically that are not present on server.

I am using the following code to make request, but the problem is getObjectsAtPath creates RKObjectRequestOperation and I need RKManagedObjectRequestOperation can any one guide me on what to do in this scenario?

With RKObjectRequestOperation the orphaned objects are not getting deleted if they no longer exist on server.

[[RKObjectManager sharedManager] getObjectsAtPath:@"/api/lists"
                                       parameters:nil
                                          success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) ...

Mapping:

RKEntityMapping *listEntityMapping = [RKEntityMapping mappingForEntityForName:@"List" inManagedObjectStore:managedObjectStore];

Response descriptor:

responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:listEntityMapping method:RKRequestMethodGET pathPattern:@"/api/lists" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

JSON:

[
    {
        "list_id": "1",
        "listName": "List Name 1"
    },
    {
        "list_id": "2",
        "listName": "List Name 2"
    },
    {
        "list_id": "5",
        "listName": "List Name 3"
    },
    {
        "list_id": "7",
        "listName": "List Name 4"
    },
    {
        "list_id": "8",
        "listName": "List Name 5"
    },
    {
        "list_id": "11",
        "listName": "List Name 6"
    },
    {
        "list_id": "12",
        "listName": "List Name 7"
    }
]
2

2 Answers

0
votes

If you are getting RKObjectRequestOperation instead of RKManagedObjectRequestOperation then you are using the wrong mapping. The operation is chosen based on the mapping which matches the request URL path pattern being an object or entity mapping. In your case your mapping needs to be an RKEntityMapping instance.

0
votes

I think you didn't configure your manager correctly to work with CoreData (and create NSManagedObjects instead of NSObjects). Make sure to set managedObjectStore on the manager you want to use to download CoreData backed objects.

http://restkit.org/api/latest/Classes/RKObjectManager.html#task_Configuring%20Core%20Data%20Integration