Is Block_copy recursive?

前端 未结 3 602
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 07:32

I have some code that essentially boils down to this:

-(void)doSomethingWithBlock:(BlockTypedef)block
{
    [Foo doSomethingElseWithBlock:^() {
        block         


        
3条回答
  •  北海茫月
    2020-12-30 07:56

    I quote the Blocks Programming Topics guide on Apple's developer documentation site:

    When you copy a block, any references to other blocks from within that block are copied if necessary—an entire tree may be copied (from the top). If you have block variables and you reference a block from within the block, that block will be copied.

    When you copy a stack-based block, you get a new block. If you copy a heap-based block, however, you simply increment the retain count of that block and get it back as the returned value of the copy function or method.

提交回复
热议问题