title: iOS Networking API Design Pattern Ideas?
body: <p>I have the following design pattern query problem. I have a web service in PHP from which I want to perform, log in authorisation, and SQL operations, some with NSDictionary responses, and some with BOOL responses.</p>
  
  <p>I have had a search for design patterns and hit this: <a href="https://stackoverflow.com/questions/24162051/best-architectural-approaches-for-building-ios-networking-applications-rest-cli">Best architectural approaches for building iOS networking applications (REST clients)</a></p>
  
  <p>Now although this post is very interesting, I don't think I need anything as complicated. I have started with a singleton object as a assetDBConnection (which is self.delegate in the below code], but I don't know whether this is the best idea.</p>
  
  <p>The only way I can think of having my assetDBConnection abstracted away from my APIWebRetrieve data retriever is to pull out and compare strings from the response. This would mean grouping the responses at the PHP service level into types, e.g. type="logon",etc,etc.</p>
  
  <pre><code>-(void)APIWebRetrieveFinished:(APIWebRetrieve *)api
  {
      NSLog(@"api:%@",[api description]);
      NSLog(@"%@",api.dataString);
      NSError *error;
      if (api.dataString) {
          NSDictionary *results=[NSJSONSerialization JSONObjectWithData:[api.dataString dataUsingEncoding:NSStringEncodingConversionAllowLossy]
                                      options:NSJSONReadingMutableContainers
                                        error:&amp;error];
  
          if ([[results objectForKey:@"type"] isEqualToString:@"logon"]){
              if ([results objectForKey:@"response"]){
                  [self.delegate loginOK];
              }else{
                  [self.delegate loginFail];
              }
         }
      }
  }
  </code></pre>
  
  <p>Any help appreciated.</p>
  
  <p><strong>Update:</strong>
  Ok, this must be pretty dull. No repsonses. I have started to add another layer in, called services. I quite like the fact that I now have this sort of code popping up:</p>
  
  <pre><code>#import "AssetDBConnection.h"
  #import "AssetDBServiceLogon.h"
  
  @implementation AssetDBConnection
  
  -(BOOL)loginWithUsername:(NSString*)user andPassword:(NSString*)password
  {
      [AssetDBService logonWithUsername:user password:password andDelegate:self];
  }
  </code></pre>
  
  <p>I just hope this is going in the right direction!</p>