Home > Mobile >  Ios for help dispatch_after and [NSTimer scheduledTimerWithTimeInterval: repeats: block]
Ios for help dispatch_after and [NSTimer scheduledTimerWithTimeInterval: repeats: block]

Time:12-25

What's the difference between the two timer?

The following code execution result how explanation?

Dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (0.5 * NSEC_PER_SEC)), dispatch_get_main_queue (), ^ {
NSLog (@ dispatch_after "1001");
});

[NSTimer scheduledTimerWithTimeInterval: 0.53 repeats: NO block: ^ (NSTimer * _Nonnull timer) {
NSLog (@ NSTimer "1002");
}];

//the results
The 2020-02-24 10:55:39. 255721 + 0800 ILGDemo [3833-454767] NSTimer 1002
The 2020-02-24 10:55:39. 274360 + 0800 ILGDemo [3833-454767] dispatch_after 1001
  •  Tags:  
  • iOS
  • Related