Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4331526
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:07:21+00:00 2026-05-21T10:07:21+00:00

I am writing an iPhone application and I have finally decided to use RestKit

  • 0

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 have the Controllers in my application be completely agnostic to RestKit. For eg. If I had a login screen, in the usual RestKit scenario (based on example programs as well as few blog entries created by the RestKit developers) you will have the controller implement the RKRequestDelegate protocol and use the RKClient to call the service in the Controller passing self ( the controller) as the delegate. I would like to hide that from the User developing the Controllers and views.

What I am thinking of is the following. I will have a LoginService which will login the user. There will be protocol LoginServiceDelegate which has two methods for success and failure. And the Controller can implement the LoginServiceDelegate and call the login Method in LoginService and get a success or failure callback. However to do this, I will need some way for my LoginService to delegate the calls back to the controller. RestKit does not allow me to do this and the only way I am able to do this by initializing the LoginService with a LoginServiceDelegate, storing that delegate as a property and calling the appropriate method in the delegate on successful login or failure.

This keeps my Controller codebase to a minimum and hides completely how the LoginService works and what framework it internally uses. The use of delegate also de-couples the Controller from the Models and so we have a good MVC thing going. However I am concerned about the implications of the Model class retaining the Controller object since it is holding onto the delegate.

How would you use RestKit ? If you think my approach is good , what would you change to make it better ? If you dont like my approach would like your feedback as to why you think it is not a good practice.

This below code snippet should give you a better idea

@protocol LoginServiceDelegate;

@interface LoginService : NSObject <RKRequestDelegate>{
    NSObject<LoginServiceDelegate> *_loginServiceDelegate;

}

@property (retain, nonatomic) NSObject <LoginServiceDelegate> *loginServiceDelegate;

- (id) initWithDelegate:(NSObject<LoginServiceDelegate>*) loginServiceDelegate;

- (void) login:(NSString *)username withPassword:(NSString *)password;

@end

@protocol LoginServiceDelegate
@optional

- (void) loginSuccess:(LoginInfo *) loginInfo;

- (void) loginFailure:(NSString *) message;

@end

Cheers !!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:07:21+00:00Added an answer on May 21, 2026 at 10:07 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an iPhone application which needs to have an option to call our
I am writing an iPhone application, and need to save the state of my
I'm currently writing an iPhone application that uses a UITabBarController with more than 5
So I'm looking at writing an iPhone application that shows things on a map.
Hey folks - I'm writing a pretty simple iPhone application. The data comes from
I'm writing server-side programs in PHP for an iPhone app. And I have no
I am writing a simple iPhone application and I am wondering if there is
I'm writing an iPhone application and I find that there are three controllers in
I'm writing an iphone application and need to show a progress bar that shows
I am writing the iPhone application and I would like to ask about the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.