Design pattern for handling a server response
I've an observer pattern on the UI that checks what's the status of an
object that handles a server connection that's trying to update a certain
field on a database.
The UI's update method receives an object containing data pairs containing
the information of what's happening with the connection. The problem is
that I'm getting tangled with a lot of ifs checking for different
possibilities.
- (void) update:(Bundle *)arg
{
if ([[arg getData:@"updatee"] isEqualToString:@"email"]){
UITableViewCell *emailCell = [[self tableView]
cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0
inSection:0]];
if ([[arg getData:@"connecting"] isEqualToString:@"true"]) {
//Email is being posted
[_emailLabel_email setText:@"Connecting..."];
[_emailLabel_set setHidden:YES];
emailCell.accessoryType = UITableViewCellAccessoryNone;
[_emailActivityIndicator startAnimating];
}else{
if ([[arg getData:@"succesfull"] isEqualToString: @"false"])
//Email was posted unsuccesfully
[[[UIAlertView alloc] initWithTitle:@"Taken Email Address"
message:@"The email address that you
entered is already in use, please
double check it"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
else{
//Email was posted succesfully.
[_emailLabel_set setText:@"Change"];
}
[_emailActivityIndicator stopAnimating];
[_emailLabel_email setText:[mng getEmail]];
[_emailLabel_set setHidden:NO];
emailCell.accessoryType =
UITableViewCellAccessoryDisclosureIndicator;
}
}
//Password cases
}
}
As the server responds with a string I'm finding difficult to avoid this
spaggetti of code.
Which would be the smarter object to send on the update method?
No comments:
Post a Comment