ios - Need assistance understanding part of blocks -


i reading ray wenderlich in-app purchases tutorial, , want understand block part of it.

  1. _completionhandler = [completionhandler copy]; why copy used assign block variable?
  2. this block:

    [[rageiaphelper sharedinstance] requestproductswithcompletionhandler:^(bool success, nsarray *products) {     if (success) {         _products = products;         [self.tableview reloaddata];     }     [self.refreshcontrol endrefreshing]; }]; 

    is passed parameter method, method present in class. how class reference class tableview , refreshcontrol ?

  1. blocks exist on stack. in order keep block around after goes out of scope need copy move heap. can treat other object , use later. in example copying block ivar can used in method.

  2. when pass block parameter encapsulates variables local scope , can access them after go out of scope. see documentation here.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -