This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.h = - (void)signInAccountWithUserName:(NSString *)userName | |
password:(NSString *)password | |
completion:(void (^)(BOOL success))completionBlock; | |
.m = - (void)signInAccountWithUserName:(NSString *)userName | |
password:(NSString *)password | |
completion:(void (^)(BOOL success))completionBlock | |
{ | |
// Notice that we are passing a BOOL back to the completion block. | |
if (completionBlock != nil) completionBlock(loginSuccessful); | |
} | |
//Call the method: | |
[self signInAccountWithUserName:@"Bob" | |
password:@"BobsPassword" | |
completion:^{ | |
[self doMethod]; //do something like call a method | |
}]; | |
OR | |
[self signInAccountWithUserName:@"Bob" | |
password:@"BobsPassword" | |
completion:^(BOOL success) { | |
if (success) { | |
[self doMethod]; //do something like call a method | |
} else { | |
// do something like display an alert | |
} | |
}]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Block that passes in an MKMapView and returns NSData called mapData | |
.h = - (void)ImageFromMapView:(MKMapView*)mapView completion:(void (^)(NSData* mapData))completionBlock; | |
.m = - (void)ImageFromMapView:(MKMapView*)mapView completion:(void (^)(NSData* mapData))completionBlock | |
{ | |
//method does what it needs to do | |
//self.data holds the NSData that was created inside this method | |
completionBlock(self.data); | |
} | |
Calling it = | |
[classWithMethod ImageFromMapView:mapView completion:^(NSData *mapData) { | |
//do something with mapData | |
}]; |
No comments:
Post a Comment