Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom RKMappingOperationDataSource implementations #1442

Closed
MigrantP opened this issue Jun 10, 2013 · 6 comments
Closed

Support custom RKMappingOperationDataSource implementations #1442

MigrantP opened this issue Jun 10, 2013 · 6 comments
Assignees
Milestone

Comments

@MigrantP
Copy link
Contributor

I would like to create my own RKMappingOperationDataSource implementation so that I can do some "Core Data like" things (e.g. updating existing objects, referencing relationships, etc) without actually involving Core Data.

A few different objects use RKMappingOperationDataSource, but they are all given either a RKObjectMappingOperationDataSource or RKManagedObjectMappingOperationDataSource instance created inside RestKit. I'm looking for a way to tell RestKit "here's my RKMappingOperationDataSource instance, please use it where necessary."

@blakewatters requested an issue be created and will provide an API sketch so that it fits properly in the system. I'll do the implementation and make a pull request.

Related Groups post: https://groups.google.com/forum/?fromgroups#!topic/restkit/JLGzjp4sjpM
Potentially related issues: #1092, #1248

@ghost ghost assigned blakewatters Jun 10, 2013
@blakewatters
Copy link
Member

Thanks for opening up the issue. I'll pull together my thoughts on this API shortly.

@blakewatters
Copy link
Member

Okay I have taken a look at this. I think all that you really need to do is:

@interface RKObjectResponseMapperOperation
+ (void)registerMappingOperationDataSourceClass:(Class<RKMappingOperationDataSource>)class;
@end

@interface RKManagedObjectResponseMapperOperation
+ (void)registerMappingOperationDataSourceClass:(Class<RKMappingOperationDataSource>)class;

You can use a static variable within the classes to implement the backing property.

Behaviors:

  1. When an instance of RKObjectResponseMapperOperation or RKManagedObjectResponseMapperOperation goes to initialize the data source it should check for a registered class before falling back to the default.
  2. It should raise an NSInvalidArgumentError in the event that the given class does not conform to the RKMappingOperationDataSource protocol.
  3. nil should unregister any existing class and fall back to the default.

@MigrantP
Copy link
Contributor Author

Sounds good, I'll get on it and get back to you with either questions or a pull request!

@MigrantP
Copy link
Contributor Author

Implemented and works in my project (with RKObjectResponseMapperOperation). I'm not sure how useful it is on RKManagedObjectResponseMapperOperation but I included it anyway as you suggested.

@blakewatters
Copy link
Member

I overhauled the implementation and added sufficient test coverage. Enjoy!

@MigrantP
Copy link
Contributor Author

Great, thanks!

4PixelsDev pushed a commit to CenterDevice/RestKit that referenced this issue Dec 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants