Search code examples
iosblock

iOS sharing code between a completion block and a method


I have a completion block (specifically FBAppCallHandler callHandler = ^(FBAppCall *call))

I have a code I want to call from this block, but also call it from a different method in the class.

How do I share code between a block and a class method?


Solution

  • You can create a method in the class for example -(void)foo. Then you can call it anywhere in the class, include the block.

    Please note not to call to self inside the block to avoid retain cycles. More info here.