I have read through the Apple documentation on Blocks but I am not quite sure how to use them in my situation. Within my application I have a Game Model. This has a method which creates a game of two users.
From a view controller I call the method in the game model, and once the game is created I need to make a callback to my view controller to say it was successful and a new VC can be pushed.
Current Code
Game Model
+(void)createNewGameAgainst:(PFUser *)user2 {
NSLog(@"createNewGameAgainst");
// First we put a HUD up for the user on the window
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
[[UIApplication sharedApplication].keyWindow addSubview:HUD];
HUD.labelText = NSLocalizedString(@"HUDCreateNewGame", @"HUD - Create New Game text");
HUD.removeFromSuperViewOnHide = YES;
[HUD showAnimated:YES whileExecutingBlock:^{
// Do something
PFObject *newGame = [PFObject objectWithClassName:@"Game"];
[newGame setObject:[PFUser currentUser] forKey:kMESGameUser1];
[newGame setObject:user2 forKey:kMESGameUser2];
[newGame saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSLog(@"succeeded game creation");
}
}];
}];
NSLog(@"end of createNewGameAgainst");
}
View Controller call
[MESGameModel createNewGameAgainst:self.gameNewOpponentuser];
I need to know how to update my method above to have a callback Block. Then update the view controller call to the method so it can execute/push a new view controller if the creation was successful.