I am messed with both completion handler and blocks while I am using them in Swift
and Objective-C
. And when I am searching blocks in Swift>
I am hope this will help.
First Step:
#import
@interface ViewController : UIViewController
-(void)InsertUser:(NSString*)userName InsertUserLastName:(NSString*)lastName widthCompletion:(void(^)(NSString* result))callback;
@end
Second Step :
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(void)InsertUser:(NSString *)userName InsertUserLastName:(NSString*)lastName widthCompletion:(void (^)(NSString* result))callback{
callback(@"User inserted successfully");
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self InsertUser:@"Ded" InsertUserLastName:@"Moroz" widthCompletion:^(NSString *result) {
NSLog(@"Result:%@",result);
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end