This seems a little strange to me that when my block
does not returns anything, I can capture it in a variable before passing it to a consumer metod. But as soon I add a return value to the block typedef
, I start getting waring
Scenario 1: Block does not returns anything //declaration
typedef void (^MYConfigureBlock)(MYFeedCell *cell, NSIndexPath *indexPath);
//usage
MYConfigureBlock block = ^(MYFeedCell *cell, NSIndexPath *indexPath){
[cell setActionDelegate:self];
return nil;
};
MYFeedSource *fds = [[MYFeedSource alloc]initWithTableView:self.tableView
configurationBlock:block];
[fds setErrorMessage:@"No feeds yet. Is everyone even alive?"];
self.feedDataSource = fds;
Every thing works perfect in the above piece of code unless I go ahead and do:
Problem here
typedef MYFeedCell* (^MYConfigureBlock)(MYFeedCell *cell, NSIndexPath *indexPath);
Now how can I re-write the following statements so that there is no error. And why does this not works as usual with a return type?
MYConfigureBlock block = ^(MYFeedCell *cell, NSIndexPath *indexPath){
[cell setActionDelegate:self];
return nil;
};
The error is
Sending 'MYFeedCell *' to parameter of incompatible type 'MYConfigureBlock' (aka 'MYFeedCell *(^)(MYFeedCell *__strong, NSIndexPath *__strong)')
The code that uses the block
- (UITableViewCell*)tableView:(UITableView*)aTableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
self.cellConfigureBlock(nil, indexPath);
}