gpt4 book ai didi

iphone - 使用 objective-c 中的 block 声明 iVar

转载 作者:行者123 更新时间:2023-12-03 19:43:44 24 4
gpt4 key购买 nike

我是 block 新手。我想创建一个 iVar NSMutableArray,我可以在 block 方法中访问它。有人可以告诉我如何使用 _block 关键字声明它吗?`

@interface ViewController : UIViewController
{
__block NSMutableArray *array;
}
@property (nonatomic, weak) NSMutableArray *array;

最佳答案

您不需要在 iVar 前面设置 __block

根据:http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/Blocks/Articles/bxVariables.html

When a block is copied, it creates strong references to object variables used within the block. If you use a block within the implementation of a method:

  • If you access an instance variable by reference, a strong reference is made to self;
  • If you access an instance variable by value, a strong reference is made to the variable.

关于iphone - 使用 objective-c 中的 block 声明 iVar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13954365/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com