Block In IOS – Tip 1

Blocks are awesome but we need to keep in mind when we access variables not declared in the scope of the block.

For example if we are using a table view and try to reload a table on completion or change its values we need to be using a local variable to do that. 

__block UITableView *tbView = [self.tableView];

__block int x;

^(error, result):{

                     x = x + 1; // block variable

                     [self.tbView addSubView:exampleView] // use the block variable instead of the global variable

}

In

Leave a Reply

Your email address will not be published. Required fields are marked *