Manual retain with ARC

后端 未结 3 1406
孤独总比滥情好
孤独总比滥情好 2021-02-01 05:06

Before ARC I had the following code that retains the delegate while an async operation is in progress:

- (void)startAsyncWork
{
    [_delegate retain];
    // ca         


        
3条回答
  •  渐次进展
    2021-02-01 05:31

    Something like this:

    - (void)startAsyncWork
    {
        id delegate = _delegate;
        dispatch_async(/* some queue */, ^{
            // do work
            [delegate doSomething];
        }
    }
    

    The block will retain the delegate as long as needed...

提交回复
热议问题