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 6033483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:29:22+00:00 2026-05-23T05:29:22+00:00

I am creating an iPhone application which communicates A LOT with my webserver. Communication

  • 0

I am creating an iPhone application which communicates A LOT with my webserver. Communication is done using JSON. Now I was wondering what is the best way to handle this. I am currently starting my 3rd try to get this code the best I can, but I am still not completely sure.

For my first try, I tried setting up a normal class with a normal delegate property (used to tell the class where the call-backs should go to, once the request is done). This method kind of failed, because of the trouble of instantiating the class, setting the delegate (object responsible for the call-backs), calling the method and then cleaning it up again. Sometimes methods of the class need to be chained, to get all the data I need for certain pages within my app, and re-instantiating the class lead to a lot of memory problems and re-using the object (service) in the chaining event, made me supply a reference to the current object to all my call-back methods… Let me say, this was not ideal.

My 2nd try was making the class a Singleton, where for each method I specified which delegate should receive the call-back calls. This caused a couple of nasty code changes (as storing the delegate object somewhere, which could be retrieved, once the request is done). Chaining methods was a lot easier when using the Singleton, but somehow I get the feeling that I am completely abusing this.

The class has about 25 to 35 methods, which can have 2 outcomes: It either worked or it failed (with a specific errorcode and message). So we are talking about 25 – 35 * 2 callback methods that need to be called.

So I am not asking for any code examples, but I was wondering if people could give me some new insights on how to solve this.

  • 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-23T05:29:23+00:00Added an answer on May 23, 2026 at 5:29 am

    I don’t know if it’s perfect, but maybe I can help you by telling how I do communication with Twitter. Basically there are a few classes doing all of this, but I’ll summarize it as if there’s only one class.

    Basically the class gets instantiated and autorelease is immediately called. It gets a delegate assigned and it makes the request. This whole process takes 3 lines of code plus one line of code for every POST parameter or GET query parameter. Authenticating with OAuth also takes one line ([request setAuthenticator:[MyNameOAuthAuthenticator authenticatorWithCredentials:...]]).

    The moment -[req execute] is called, it calls [self retain] to compensate for the autorelease. When the request itself is done (or errored), the delegate is informed with the JSON object, and [self release] is called. This takes care of all memory issues.

    My code is currently built in a way where it only needs a minimum of one (!) line to execute: [[[[MyRequest alloc] initWithHTTPMethod:httpMethodGET andURL:[NSURL URLWithString:...]] autorelease] execute]

    Maybe this helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using iPhone OS 4 and creating an application. I've a webview, over which
we are creating an application using HTML5 for Iphone, IPAD and Android. Now the
I am creating an iphone application in which some calculations are done for calculating
I am creating an iphone application in which I have to upload photos using
I am running creating an iPhone application which performs a costly operation and I
I am creating an application for the iPhone which involves having more than one
I have recently started creating an iPhone application using Appcelerator's Titanium. Since the application
I am creating a mobile web application using asp.net. The application must support iPhone,
I'm creating an application for iPhone which needs to handle large data. So, I
I Am creating an iPhone application which displays an UITableView at the start with

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.