GCD和NSThread延时执行对比

1、NSThread:

[self performSelector:@selector(performSome:)
               withObject:self
               afterDelay:3.f];
    
[[self class] cancelPreviousPerformRequestsWithTarget:self];

优点:NSThread 延时时间更精确;方法可控,可以取消执行。

缺点:代码量较大;

 

2、GCD:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        NSLog(@"end");
    });

优点:代码紧凑;
缺点:时间有误差,不可控;

posted @ 2016-06-26 12:12  Kingdev  阅读(618)  评论(0编辑  收藏  举报