ink
ink

Reputation: 317

RestKit 0.20.3 + Core Data - Skip mapping operation

I'm working on an app and I need to sync objects with my API. I use RestKit 0.20.3.

The sync process begins by pulling objects from the server, and then pushes the objects that have been modified inside the app by the user. Therefore, during the pull step, I need to ignore the objects that have been modified locally, so they won't be overriden with the server version.

I use CoreData for my objects, and I set a boolean property "modified" to YES for those that are locally modified. So after a GET during the sync, I need to skip the mapping step for the objects having this "modified" property, but I can't find exactly how I'm supposed to do that.

The only way I've found so far is by adding a condition directly inside the RKMappingOperation, but it's dirty.

Is there a better way to do that in RestKit (and by not modifying the RestKit code)?

Upvotes: 1

Views: 173

Answers (1)

ink
ink

Reputation: 317

Well, I kept on investigating, and I just found the solution.

It's actually possible to register a custom class as RKResponseMapperOperation data source :

[RKManagedObjectResponseMapperOperation registerMappingOperationDataSourceClass:[MyCustomDataSource class]];

MyCustomDataSource should implement the RKMappingOperationDataSource protocol. Mine inherits from RKManagedObjectMappingOperationDataSource since I'm using managed objects through Core Data.

@interface SUManagedObjectMappingOperationDataSource : RKManagedObjectMappingOperationDataSource
@end

In the implementation, I just overridden the following method to add my skipping logic to the existing one :

- (BOOL)mappingOperationShouldSkipPropertyMapping:(RKMappingOperation *)mappingOperation

Upvotes: 6

Related Questions