Some questions about objective-c block and copy

前端 未结 3 769
说谎
说谎 2020-12-30 16:37

I write some code use objective-c block, but the result confused me.

@interface MyTest : NSObject

@end

@implementation MyTest

- (void)test {
    NSArray *         


        
3条回答
  •  一个人的身影
    2020-12-30 16:47

    All three of these crash for me (although I suspect the lack of a copy on the first element of array3 is probably an oversight.) A block has to be copied if you want it to outlive the scope in which it was created. Unless you specifically know that a method copies the object you pass into it, you need to copy it yourself.

提交回复
热议问题