iOS development methods for delaying the execution of a method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.