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