objective-c - Block_copy 是递归的吗?

标签 objective-c cocoa objective-c-blocks

我有一些代码基本上可以归结为:

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

Foo doSomethingElseWithBlock: 在它收到的 block 上调用 Block_copyBlock_release。这在外部范围是否也是必要的,或者内部 Block_copy 会处理这个吗?

最佳答案

我引用 Blocks Programming Topics Apple 开发人员文档网站上的指南:

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.

关于objective-c - Block_copy 是递归的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6420656/

相关文章:

ios - 按下后退按钮时 UIScrollView 卡住了吗?

iOS: block 和 ivars

Objective-C – cellForRowAtIndexPath 导致按钮框架改变大小?

objective-c - NSDecimalNumber 和 large unsigned long long(64 位)整数

objective-c - NSString 特殊字符编码

objective-c - 将 block 与 LLVM GCC 4.2 一起使用时出现编译问题

cocoa - Cocos2D、 block 和将应用程序移动到后台

iphone - 仪器中的红线

ios - Objective-C block 参数类型推断

macos - 在 Cocoa 框架中包含插件