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.
I have had a search for design patterns and hit this: Best architectural approaches for building iOS networking applications (REST clients)
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.
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.
-(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:&error];
if ([[results objectForKey:@"type"] isEqualToString:@"logon"]){
if ([results objectForKey:@"response"]){
[self.delegate loginOK];
}else{
[self.delegate loginFail];
}
}
}
}
Any help appreciated.
Update: 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:
#import "AssetDBConnection.h"
#import "AssetDBServiceLogon.h"
@implementation AssetDBConnection
-(BOOL)loginWithUsername:(NSString*)user andPassword:(NSString*)password
{
[AssetDBService logonWithUsername:user password:password andDelegate:self];
}
I just hope this is going in the right direction!