Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior

后端 未结 5 1730
无人及你
无人及你 2020-12-04 17:48

Given the following:

- (void) someMethod
{
    dispatch_async(dispatch_get_main_queue(), ^{
        myTimer = [NSTimer scheduledTimerWithTimeInterval: 60
            


        
5条回答
  •  醉梦人生
    2020-12-04 17:59

    Replacing myTimer by self->myTimer would fix your warning.

    When you use an iVar _iVar in the code, the compiler will replace the code by self->_iVar, and if you use it inside a block, the block will capture self instead of the iVar itself. The warning is just to make sure the the developer understand this behaviour.

提交回复
热议问题