Several run methods of Runloop

Source: Internet
Author: User

Running a Loop1,run:


Puts the receiver into a permanent loop, during which time it processes data from all attached input sources.


Discussion

If no input sources or timers is attached to the run loop, this method exits immediately;

Otherwise, it runs the receiver in the Nsdefaultrunloopmode by repeatedly invoking runmode:befored Ate:.

In other words, this method effectively begins a infinite loop that processes data from the run loop ' s input sources and Timers.

Manually removing all known input sources and timers from the run loop are not a guarantee that the run loop would exit. OS X can install and remove additional input sources as needed to process requests targeted at the receiver ' s thread. Those sources could therefore prevent the run loop from exiting.


If you want the "run loop to terminate", you shouldn ' t use this method. Instead, use one of the other run methods and also check other arbitrary conditions of your own, in a loop. A Simple example would is:

BOOL shouldkeeprunning = YES; Globalnsrunloop *therl = [Nsrunloop currentrunloop];while (shouldkeeprunning && [Therl runmode: Nsdefaultrunloopmode beforedate:[nsdate Distantfuture]]);

Where shouldkeeprunning is set to NO somewhere else in the program.


2,-runmode:beforedate:


Runs the loop once, blocking for input in the specified mode until a given date.


Return Value

YES If the run loop ran and processed an input source or if the specified timeout value is reached; Otherwise,no If the run loop could not be started.


Discussion

If no input sources or timers is attached to the run loop, this method exits immediately and returns no;


Otherwise, it returns after either the first input source is processed or limitdate is reached. (only one event is processed at a time, so rununtildate and run will call this method in a loop)


Manually removing all known input sources and timers from the run loop does not guarantee, that the run loop would exit Imme Diately. OS X may install and remove additional input sources as needed to process requests targeted at the receiver ' s thread. Those sources could therefore prevent the run loop from exiting.


NOTE

A timer is not considered an input source and may fire multiple times while waiting for this method to return




3,-rununtildate:


If no input sources or timers is attached to the run loop, this method exits immediately;


Otherwise, it runs the receiver in the Nsdefaultrunloopmode by repeatedly invoking Runmode:beforedate:u Ntil the specified expiration date.













Several run methods of Runloop

Related Article

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.