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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:57:51+00:00 2026-05-27T04:57:51+00:00

I am writing a small iOS app that queries a XML REST webservice. The

  • 0

I am writing a small iOS app that queries a XML REST webservice. The networking framework in use is AFNetworking.

Situation

To query the webservice I subclassed AFHTTPClient:

@interface MyApiClient : AFHTTPClient

and in the implementation I make that available as a singleton:

+ (MyApiClient *)sharedClient {
    static MySharedClient *_sharedClient = nil;
    static dispatch_once_t oncePredicate;
    dispatch_once(&oncePredicate, ^{
        _sharedClient = [[self alloc] initWithBaseUrl:[NSUrl URLWithString:@"http://url.to.the.webservice"]];
    });

    return self;
} 

and in initWithBaseURL I tell AFNetworking to expect XML content:

[self registerHTTPOperationClass:[AFXMLRequestOperation class]];

Now I can call getPatch on the singleton from my ViewController and in the success block start parsing my returned XML. In NSXMLParserDelegate methods in the ViewController I can then pick the parts of the XML I am interested in and do stuff with it.

Problem

I want to have methods in my HTTPClient singleton that handle everything related to the webservice and return data models or list of models instead of XML.

For example I want to do something like this:

ServerModel *status = [[MyApiClient sharedClient] getServerStatus];

The ApiClient would then internally call the webservice, parse the XML and return the model.
How can I do that? Normally I would use a delegate that gets called once the XML is parsed, but due to the singleton nature of the ApiClient there could be multiple delegates?

Hope someone can shed light on this, thanks!

  • 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-27T04:57:52+00:00Added an answer on May 27, 2026 at 4:57 am

    (Apologies in advance for this “sort-of” answer, but we’re working towards a better solution…)

    You need to take a step back and think about your design carefully.

    You’re having problems because you’ve got an idea that something in your design needs to be a singleton, but either:

    1) that’s not actually necessary,

    2) something might already exist that does that job for you (e.g. the HTTP lib you’re using),

    or

    3) You’re making the wrong thing a singleton, or you haven’t portioned out your design into the appropriate parts to work well with the singleton idea

    So, can you tell me explicitly why you’re going for a singleton approach? Is it just to ensure that only one network request can happen at once? Is there any notion of statefulness in your singleton object? Then I’ll update this answer or comment, etc.

    (Digression: I would also add that in some cases there might be a true need for a ‘strong‘ singleton — by which I mean that there really is only one possible instance, and that mechanism is baked right into your object, as you are doing – but this isn’t it. The alternative is a ‘weak‘ singleton, by which I mean your core object that actually does the work has a plain init method as usual, but shared access to a common object goes via another object, which is a kind of simple ‘factory’ that instantiates/holds the shared instance. The advantage of this weak singleton idea is that your code is more re-usable in different contexts – e.g. you could decide to do multiple HTTP requests/sessions concurrently at a later time – and it sometimes makes writing tests less problematic).

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

Sidebar

Related Questions

I've been writing a small app that basically loads its content from locally stored
I'm writing a small painting app for iOS. I'm subclassing a UIView ad performing
Writing a small app that ( among other things ) lets users upload a
I'm writing a small/beta testing program that will be put to use in my
I'm writing a small sample app using Ember.js. My goal is to determine use
Coming from a PHP background, I'm used to writing small functions that return a
Im just writing a small Ajax framework for re-usability in small projects and i've
I'm writing a small agent in java that will play a game against other
I'm writing a small non-commercial web app, and I'm wondering how to pass data
Hi am writing small app for posting twitts on twitter.com I manage to create

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.