I was studying blocks and it seems pretty impressive to use. But then I came to know that we can use blocks in functions as variable and its main use is when we want to do some async work that after getting result of something we have to perform some action.
I looked into a lot of resources and got what they were doing. I tried to do the same just by passing string like this:
Defining a block as parameter in .h file
typedef void(^sudBlock)(NSString * myname);
- (void)blockAsLastParam:(NSString*)name completion:(sudBlock)blockName;
Implementing a block as parameter in .m file
-(void) blockAsLastParam:(NSString *)name completion:(sudBlock)blockName{
blockName(name);
}
[self blockAsLastParam:@"sudh" completion:^(NSString *myname) {
NSLog(@"This is block %@",myname);
}];
So here I am passing "sudh" as a string and getting it again.
Still I am not sure how the while thing works. Is there a tutorial where how things are done is perfectly captured with drawings.
I have read a lot of articles but they only tell us the way it needs to be implemented but don,t tell why this implementation do this stuff. Also how does parameter transfer is going on in functions called .