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

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

Given the following:

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


        
5条回答
  •  Happy的楠姐
    2020-12-04 18:12

    This fixes my problem for Xcode 9.3

    - (void) someMethod{
    
        __weak MyClass *wSelf = self;
    
        dispatch_async(dispatch_get_main_queue(), ^{
    
        MyClass *sSelf = wSelf;
        if(sSelf != nil){
            wself.myTimer = [NSTimer scheduledTimerWithTimeInterval: 60
                                                           target: self
                                                         selector:@selector(doSomething)
                                                         userInfo: nil
                                                          repeats: NO];
           }
    
       });
    }
    

提交回复
热议问题