Good article link: https://www.jianshu.com/p/b9426458fcf6
// Runloop responsible for the listener 1. 2. Ensure that the program does not quit
// currentRunLoop RunLoop current thread
NSTime * timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(timerMethod) userInf:nil repets:YES];
[[NSRunLoop currentRunLoop] addTimer: h forModel: NSDefaultRunLoopModel];
/*
NSDefaultRunLoopModel default mode
UITrackingRunLoopModel UI mode
NSRunLoopCommonModes UI & default
*/
- (void)timerMethod
{
NSLog (@ "come");
}
When the timer added to the Tableview, when dragging timer is not performed?
Every second, call timer default mode, when runloop wakes up on the implementation of tasks, executing the rest went, because the UI mode highest priority, when the drag runloop can only handle UI mode drag, drag when when pulled, the default mode queue is able to receive requests every second, but runloop no way to perform, due to the implementation of UI mode
So the Model UI mode can be changed without affecting the printing while dragging
[[NSRunLoop currentRunLoop] addTimer: h forModel: UITrackingRunLoopModel];
But the drag stop printing stops because the UI mode can only be awakened by UI events,
So to add model in each mode
[[NSRunLoop currentRunLoop] addTimer: h forModel: UITrackingRunLoopModel];
[[NSRunLoop currentRunLoop] addTimer: h forModel: NSDefaultRunLoopModel];
The simplest use NSRunLoopCommonModes
The question is, if there is time-consuming operation in timerMethod, then will Caton, so the timer thread when added to the sub-drag
while (true) is dead code
If not [[NSRunLoop currentRunLoop] run]; timerMethod not performed because the thread is a local variable, on the release executing the viewdidload
If you add timer must be turned on in the child thread in the child thread will be performed, because the main thread is automatically created runloop main thread is created when you create so runloop without having to manually turn on the main thread
The main thread ------------------
UIKit framework is not thread safe
The main thread is the UI thread, the main thread UI refresh all
runloop equivalent thread interfaces provided by the outside world, so to call external, called the event processing task runLoop
Apple did not give wear a runloop interface, but Apple itself is created runloop, wear a eg when you first get: currentRunLoop
-----------------------------------------------------------------------------------------------------
------------------------- source -------------------
Apple's official explanation
Divided according to the classification function call stack Source of Source0 and Source1 (kernel event with 1 source0 opposite)
Screenshot have _CFRunLoopDoSource0 top
The main thread is created with the GCD is to create Source
----------------------------------------------------------------------
Add to runloop observer -------------- -----------
NSMutableArray is a pointer to a heap area, the heap area, there is a pointer to another block of memory, the other memory heap memory is for storing data
Top screenshot is optimized by observer do tableview
Below is a part of the code, to load a large multi FIG FIG, page modular simulated load
Video name January 27 --Runloop
About performance tuning video, there are video memory leak detection and leak locating position