Best way to use RestKit in an iPhone Application Best way to use RestKit in an iPhone Application ios ios

Best way to use RestKit in an iPhone Application


I'm the author of RestKit and we advocate using such patterns to build higher level abstractions on top of RestKit. I generally build my callbacks and such around a model object rather than creating a new LoginService type of object, but either way is fine. In my example, you would do something like:

@implementation RKUser- (void)loginWithDelegate:(NSObject<RKUserAuthenticationDelegate>*)delegate {}@end@protocol RKUserAuthenticationDelegate- (void)userDidLogin:(RKUser*)user;- (void)userDidFailLoginWithError:(RKUser*)user;- (void)userDidLogout:(RKUser*)user@end

In any case, the other thing I would recommend is changing your delegate from a retain to an assign. In your dealloc method, you can do a couple of things:

  1. Nil out the delegate so you won't get crashed by a callback
  2. Ask the request queue to cancel any requests: [[RKRequestQueue sharedQueue] cancelRequestsWithDelegate:self];

That's about all that you need to worry about from a memory management / house-keeping perspective. The other thing that I typically always wind up doing is creating notifications for my authentication life-cycle events. You just always wind up needing to observe them to update UI somewhere in my experience.

You are on the right track and the design is fine.

Best,Blake