Invoke block iOS

Matrosov Alexander picture Matrosov Alexander · Feb 28, 2012 · Viewed 17.9k times · Source

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?

Answer

Julien picture Julien · Feb 28, 2012

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