title: AFNetworking HTTPClient subclass with XMLParser
body: <p>I am writing a small iOS app that queries a XML REST webservice. The networking framework in use is <a href="https://github.com/AFNetworking/AFNetworking" rel="nofollow">AFNetworking</a>.</p>
  
  <h2>Situation</h2>
  
  <p>To query the webservice I subclassed AFHTTPClient:</p>
  
  <pre><code>@interface MyApiClient : AFHTTPClient
  </code></pre>
  
  <p>and in the implementation I make that available as a singleton:</p>
  
  <pre><code>+ (MyApiClient *)sharedClient {
      static MySharedClient *_sharedClient = nil;
      static dispatch_once_t oncePredicate;
      dispatch_once(&amp;oncePredicate, ^{
          _sharedClient = [[self alloc] initWithBaseUrl:[NSUrl URLWithString:@"http://url.to.the.webservice"]];
      });
  
      return self;
  } 
  </code></pre>
  
  <p>and in initWithBaseURL I tell AFNetworking to expect XML content:</p>
  
  <pre><code>[self registerHTTPOperationClass:[AFXMLRequestOperation class]];
  </code></pre>
  
  <p>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.</p>
  
  <h2>Problem</h2>
  
  <p>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.</p>
  
  <p>For example I want to do something like this:</p>
  
  <pre><code>ServerModel *status = [[MyApiClient sharedClient] getServerStatus];
  </code></pre>
  
  <p>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?</p>
  
  <p>Hope someone can shed light on this, thanks!</p>