About IOS Runtime Runloop 2

Source: Internet
Author: User

Runtime

That is, the runtime component, a plain C-written base library.

We usually write in the OC Code, the program runs the process, in fact, the final turn to the runtime C language code objective-c written out of the program must be run runtime to normal operation.
NSObject implementation (in fact, and runtime do docking, put themselves into the runtime, so that the subclass of inheritance automatically Access Runtime)

what can runtime do?

Runtime also allows us to query and dynamically extend the variables, methods, properties, and protocols of all OBJECTIVE-C classes through standard interfaces (C functions).
Another important feature implementation of Runtime is the dispatch of messages, and Objc_msgsend is the most basic entry function for message dispatch.

The following two methods have equivalent effect on message sending;
OC: [[Mjperson alloc] init];
Runtime:objc_msgsend (Objc_msgsend ("Mjperson", "Alloc"), "Init")

ISA is a pointer to the Objective-c class type, and the instance object has an Isa attribute, which points to class;

The class also has an Isa attribute, pointing to Meteclass;

Common Runtime methods:

123 objc_setassociatedobject --- Set Association class_addproperty ( [someclass class , "name" , attrs, 3) ; ---> Add property class_addmethod ( [someclass class] , @selector (setname:) (imp) namesetter, "[email  protected]:@ ") ; ---> Add method

Runloop

Runloop is the concept of a loop, or, to be precise, a loop in a thread is actually an object that inherits NSObject.

Nsrunloop's role is to have something to do when the current Nsrunloop thread is working, nothing to do to make the current Nsrunloop thread hibernate;

Each thread has its corresponding runloop, but the default non-main thread of Runloop is not running, you need to add at least one event source for Runloop, and then go to run it. In general, it is not necessary for us to enable thread runloop unless you have a long time to detect an event in a separate thread.

Bean Electric Rain from http://blog.zuics.com/

1234567891011 BOOL pagestillloading = YES; While (pagestillloading) { mclog(@"Runloop cycle"); [[nsrunloop currentrunloop] runmode:nsdefaultrunloopmode beforedate: [nsdate distantfuture]]; }mclog(@"loop over"); Most commonly used is arunloop Usage If running the above code will find that it will get stuck and will not print "loop over"! Until pagestillloading is set to NO

About IOS Runtime Runloop 2

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.