定时器

#-----GCD
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
 });
DispatchQueue.main.asyncAfter(deadline: .now()+0.4) {
 }
@property (nonatomic,strong) NSTimer *timerReloadList;
- (NSTimer *)timerReloadList
{
    if (!_timerReloadList) {
        _timerReloadList = [NSTimer scheduledTimerWithTimeInterval:2
                                                            target:self
                                                          selector:@selector(updateDeviceListShow)
                                                          userInfo:nil
                                                           repeats:YES];
    }
    return _timerReloadList;
}
- (void)updateDeviceListShow{
    NSLog(@"xxxx");
}
  [self.timerReloadList setFireDate:[NSDate distantPast]]; //开启
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [self.timerReloadList invalidate];//释放
    self.timerReloadList = nil;
}

你可能感兴趣的:(定时器)