Best way to use RestKit in an iPhone Application

前端 未结 1 678
野的像风
野的像风 2021-01-29 18:03

I am writing an iPhone application and I have finally decided to use RestKit as the framework for connecting to REST Services.

The way I am thinking of building is to h

相关标签:
1条回答
  • 2021-01-29 19:00

    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

    0 讨论(0)
提交回复
热议问题