Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke block iOS

I try to invoke some block, but I run into a EXC_BAD_ACCESS.

-(void) methodA {
   self.block = ^ {
       [self methodB];
   };
}

-(void) webViewDidFinishLoad:(UIWebView *)webView {
       [block invoke]; // error here (block is not valid id type).
}

-(void)methodB {
    //do something
}

Any thoughts on why this is happening?

like image 571
Matrosov Oleksandr Avatar asked Feb 28 '12 14:02

Matrosov Oleksandr


2 Answers

if you want to invoke the block you can simply do this block(); instead of [block invoke];

for more details, see the Block Programming Topics

like image 187
Julien Avatar answered Oct 21 '22 12:10

Julien


You should use copy attribute when you are declaring block property. Like:

@property (nonatomic, copy)   id block;
like image 37
murat Avatar answered Oct 21 '22 12:10

murat