In real-world development, there are times when you need to delay execution of a method or a piece of code, summarizing two ways to defer execution of a piece of code:
1.
[Self performSelector:withObject:afterDelay:];
The method of deferred execution (SEL) is a method in OC. The first parameter is the method to be executed, the second parameter is the parameter of the method being executed, and can have either a parameter or nil. The third parameter is how long it takes to execute the method, which is single-threaded.
2.
Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (2 * nsec_per_sec)), Dispatch_get_main_queue (), ^{
[Self sentmessage:rmsg type:czmessagetypeother];
});
Defer execution of the contents of the code block. This method is multithreaded, and you can specify the queue in which to execute the contents of the code block, and then decide on which thread to execute. Because of the limited level, for the moment to understand so much. New understandings will continue to be shared in the future.
iOS development methods for delaying the execution of a method