{"id":1411,"date":"2018-11-23T13:01:50","date_gmt":"2018-11-23T05:01:50","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=1411"},"modified":"2018-11-27T17:20:54","modified_gmt":"2018-11-27T09:20:54","slug":"runloop%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%bf%90%e8%a1%8c%e9%80%bb%e8%be%91","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2018\/11\/23\/1301501411.html","title":{"rendered":"RunLoop\u7684\u57fa\u672c\u8fd0\u884c\u903b\u8f91"},"content":{"rendered":"<p><strong>\u4e00\u3001\u57fa\u672c\u903b\u8f91\u63cf\u8ff0\uff1a<\/strong><\/p>\n<p>1\u3001\u901a\u77e5Observer\uff1a\u8fdb\u5165Loop<br \/>\n2\u3001\u901a\u77e5Observer\uff1a\u5373\u5c06\u5904\u7406Timers<br \/>\n3\u3001\u901a\u77e5Observer\uff1a\u5373\u5c06\u5904\u7406Sources<br \/>\n4\u3001\u5904\u7406Blocks<br \/>\n5\u3001\u5904\u7406Source0(\u4e2d\u95f4\u53ef\u80fd\u4f1a\u5904\u7406Blocks)<br \/>\n6\u3001\u5982\u679c\u5b58\u5728Source1\uff0c\u8df3\u8f6c\u5230\u7b2c8\u6b65<br \/>\n7\u3001\u901a\u77e5Observer\uff0c\u5f00\u59cb\u4f11\u7720 (\u7b49\u5f85\u5524\u9192)<br \/>\n8\u3001\u901a\u77e5Observer\uff0c\u7ed3\u675f\u4f11\u7720 (\u88ab\u5524\u9192)<br \/>\n8.1\u3001\u5904\u7406Timer<br \/>\n8.2\u3001\u5904\u7406GCD Async To Main Queur<br \/>\n8.3\u3001\u5904\u7406Source1<br \/>\n9\u3001\u5904\u7406Blocks<br \/>\n10\u3001\u6839\u636e\u524d\u9762\u7684\u6267\u884c\u7ed3\u679c\uff0c\u51b3\u5b9a\u5982\u4f55\u64cd\u4f5c<br \/>\n10.1\u3001\u56de\u5230\u7b2c2\u6b65<br \/>\n10.2\u3001\u9000\u51faLoop<br \/>\n11\u3001\u901a\u77e5Observer\uff0c\u9000\u51faLoop<\/p>\n<p><strong>\u4e8c\u3001\u6dfb\u52a0Observer\u5bf9\u8c61\u89c2\u5bdfRunLoop\u72b6\u6001<\/strong><\/p>\n<pre lang=\"objc\" line=\"1\">\r\n#import \"ViewController.h\"\r\n#import <objc\/runtime.h>\r\n\r\n@implementation ViewController\r\n- (void)viewDidLoad\r\n{\r\n    [super viewDidLoad];\r\n    CFRunLoopAddObserver(CFRunLoopGetMain(), CFRunLoopObserverCreateWithHandler(kCFAllocatorDefault, kCFRunLoopAllActivities, true, 0, ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {\r\n        switch (activity) {\r\n            case kCFRunLoopEntry:\r\n                NSLog(@\"kCFRunLoopEntry\");\r\n                break;\r\n            case kCFRunLoopBeforeTimers:\r\n                NSLog(@\"kCFRunLoopBeforeTimers\");\r\n                break;\r\n            case kCFRunLoopBeforeSources:\r\n                NSLog(@\"kCFRunLoopBeforeSources\");\r\n                break;\r\n            case kCFRunLoopBeforeWaiting:\r\n                NSLog(@\"kCFRunLoopBeforeWaiting\");\r\n                break;\r\n            case kCFRunLoopAfterWaiting:\r\n                NSLog(@\"kCFRunLoopAfterWaiting\");\r\n                break;\r\n            case kCFRunLoopExit:\r\n                NSLog(@\"kCFRunLoopExit\");\r\n                break;\r\n            default:\r\n                break;\r\n        }\r\n    }), kCFRunLoopDefaultMode);\r\n}\r\n\r\n@end<\/pre>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<br \/>\n2018-11-23 13:00:26.772786+0800 runtime[5318:1718588] kCFRunLoopBeforeTimers<br \/>\n2018-11-23 13:00:26.772945+0800 runtime[5318:1718588] kCFRunLoopBeforeSources<br \/>\n2018-11-23 13:00:26.773104+0800 runtime[5318:1718588] kCFRunLoopBeforeTimers<br \/>\n2018-11-23 13:00:26.773196+0800 runtime[5318:1718588] kCFRunLoopBeforeSources<br \/>\n2018-11-23 13:00:26.773359+0800 runtime[5318:1718588] kCFRunLoopBeforeTimers<br \/>\n2018-11-23 13:00:26.773446+0800 runtime[5318:1718588] kCFRunLoopBeforeSources<br \/>\n2018-11-23 13:00:26.774171+0800 runtime[5318:1718588] kCFRunLoopBeforeTimers<br \/>\n2018-11-23 13:00:26.774318+0800 runtime[5318:1718588] kCFRunLoopBeforeSources<br \/>\n2018-11-23 13:00:26.774703+0800 runtime[5318:1718588] kCFRunLoopBeforeTimers<br \/>\n2018-11-23 13:00:26.774982+0800 runtime[5318:1718588] kCFRunLoopBeforeSources<br \/>\n2018-11-23 13:00:26.775247+0800 runtime[5318:1718588] kCFRunLoopBeforeTimers<br \/>\n2018-11-23 13:00:26.775529+0800 runtime[5318:1718588] kCFRunLoopBeforeSources<br \/>\n2018-11-23 13:00:26.776696+0800 runtime[5318:1718588] kCFRunLoopBeforeTimers<br \/>\n2018-11-23 13:00:26.777218+0800 runtime[5318:1718588] kCFRunLoopBeforeSources<br \/>\n2018-11-23 13:00:26.777738+0800 runtime[5318:1718588] kCFRunLoopBeforeTimers<br \/>\n2018-11-23 13:00:26.778066+0800 runtime[5318:1718588] kCFRunLoopBeforeSources<br \/>\n2018-11-23 13:00:26.778600+0800 runtime[5318:1718588] kCFRunLoopBeforeTimers<br \/>\n2018-11-23 13:00:26.778890+0800 runtime[5318:1718588] kCFRunLoopBeforeSources<br \/>\n2018-11-23 13:00:26.779473+0800 runtime[5318:1718588] kCFRunLoopBeforeTimers<br \/>\n2018-11-23 13:00:26.779768+0800 runtime[5318:1718588] kCFRunLoopBeforeSources<br \/>\n2018-11-23 13:00:26.780083+0800 runtime[5318:1718588] kCFRunLoopBeforeWaiting<br \/>\n2018-11-23 13:00:27.206960+0800 runtime[5318:1718588] kCFRunLoopAfterWaiting<br \/>\n2018-11-23 13:00:27.207376+0800 runtime[5318:1718588] kCFRunLoopBeforeTimers<br \/>\n2018-11-23 13:00:27.207481+0800 runtime[5318:1718588] kCFRunLoopBeforeSources<br \/>\n2018-11-23 13:00:27.207573+0800 runtime[5318:1718588] kCFRunLoopBeforeWaiting<br \/>\n2018-11-23 13:00:27.207710+0800 runtime[5318:1718588] kCFRunLoopAfterWaiting<br \/>\n2018-11-23 13:00:27.207817+0800 runtime[5318:1718588] kCFRunLoopBeforeTimers<br \/>\n2018-11-23 13:00:27.207917+0800 runtime[5318:1718588] kCFRunLoopBeforeSources<br \/>\n2018-11-23 13:00:27.208026+0800 runtime[5318:1718588] kCFRunLoopBeforeWaiting<br \/>\n2018-11-23 13:00:28.161836+0800 runtime[5318:1718588] kCFRunLoopAfterWaiting<br \/>\n2018-11-23 13:00:28.162695+0800 runtime[5318:1718588] kCFRunLoopBeforeTimers<br \/>\n2018-11-23 13:00:28.162891+0800 runtime[5318:1718588] kCFRunLoopBeforeSources<br \/>\n2018-11-23 13:00:28.163063+0800 runtime[5318:1718588] kCFRunLoopBeforeWaiting<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u57fa\u672c\u903b\u8f91\u63cf\u8ff0\uff1a 1\u3001\u901a\u77e5Observer\uff1a\u8fdb\u5165Loop 2\u3001\u901a\u77e5Observer\uff1a\u5373\u5c06\u5904\u7406Timers 3\u3001\u901a\u77e5Observer\uff1a\u5373\u5c06\u5904\u7406Sources 4\u3001\u5904\u7406Blocks 5\u3001\u5904\u7406Source0(\u4e2d\u95f4\u53ef\u80fd\u4f1a\u5904\u7406Blocks) 6\u3001\u5982\u679c\u5b58\u5728Source1\uff0c\u8df3\u8f6c\u5230\u7b2c8\u6b65 7\u3001\u901a\u77e5Observer\uff0c\u5f00\u59cb\u4f11\u7720 (\u7b49\u5f85\u5524\u9192) 8\u3001\u901a\u77e5Observer\uff0c\u7ed3\u675f\u4f11\u7720 (\u88ab\u5524\u9192) 8.1\u3001\u5904\u7406Timer 8.2\u3001\u5904\u7406GCD Async To Main Queur 8.3\u3001\u5904\u7406Source1 9\u3001\u5904\u7406Blocks 10\u3001\u6839\u636e\u524d\u9762\u7684\u6267\u884c\u7ed3\u679c\uff0c\u51b3\u5b9a\u5982\u4f55\u64cd\u4f5c 10.1\u3001\u56de\u5230\u7b2c2\u6b65 10.2\u3001\u9000\u51faLoop 11\u3001\u901a\u77e5Observer\uff0c\u9000\u51faLoop \u4e8c\u3001\u6dfb\u52a0Observer\u5bf9\u8c61\u89c2\u5bdfRunLoop\u72b6\u6001 #import &#8220;ViewController.h&#8221; #import @implementation ViewController &#8211; (void)viewDidLoad { [super viewDidLoad]; CFRunLoopAddObserver(CFRunLoopGetMain(), CFRunLoopObserverCreateWithHandler(kCFAllocatorDefault, kCFRunLoopAllActivities, true, 0, ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) { switch (activity) { case kCFRunLoopEntry: NSLog(@&#8221;kCFRunLoopEntry&#8221;); break; case kCFRunLoopBeforeTimers: NSLog(@&#8221;kCFRunLoopBeforeTimers&#8221;); break; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[190,180],"class_list":["post-1411","post","type-post","status-publish","format-standard","hentry","category-project","tag-runloop","tag-180"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=1411"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1411\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=1411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=1411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=1411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}