Assignment to ivar in a Block via weak pointer

前端 未结 2 1243
情深已故
情深已故 2020-12-31 18:33

I have a read-only property isFinished in my interface file:

typedef void (^MyFinishedBlock)(BOOL success, NSError *e);

@interface TMSyncBase :         


        
2条回答
  •  执笔经年
    2020-12-31 19:02

    A slight workaround is to create a method and let that the compiler handle it for you. Works fine, but I'm not sure if it is the correct way. Can someone tell if its correct?

    __weak MyClass *weakSelf = self;
    MyFinishedBlock finishedBlockWrapper = ^(BOOL success, NSError *e) {
        [weakSelf makeIsFinishedYes];
    };
    
    - (void)makeIsFinishedYes
    {
        isFinished_ = YES;
    }
    

提交回复
热议问题