Yes, we can pass the Block as argument in function. Here it is :
let suppose i create a class Downloader
First declare a Block in Downloader.h:
typedef void (^DownloadComplete)(double,double,double,BOOL,id,id);
then declare method as following in Downloader.m:
-(void)startdownload:(id)Object andCompletion:(DownloadComplete)completion;
And here it is implementation :
-(void)startdownload:(id)Object andCompletion:(DownloadComplete)completion{
// here will come you logic and other formation after that simply call the block
completion(0,0,0,YES,response,Object);
}
And in this way we can call that method in which Block as function argument:
Downloader *downloader=[[Downloader alloc] init];
[downloader startdownload:self andCompletion:^(double bytesread, double totalBytesRead, double totalBytesExpectedToRead, BOOL flag, id object, id object) {
// Here you can handle the response and do what you want to do with it.
}
0 Comment(s)