IOS RunLoop 3. iosrunloop

Source: Internet
Author: User

IOS RunLoop 3. iosrunloop

After two introductions, I want to have a simple understanding of RunLoop, at least I don't know anything about it.

In this article, I would like to make a simple supplement to "CFRunLoopObserverRef.

Let's talk about it before adding it.

ARC is rarely seen in current development.

But that is for the OC object.

CFRunLoopObserverRef belongs to CF (Core Foundation)

So we need to manually release it.

The rules are as follows:

All objects created by functions with creat copy retain and other components must be released at the end, that is, Release.

/// ViewController. m // CX RunLoop analysis // Created by ma c on 16/3/29. // Copyright©2016 xubaoaichiyu. all rights reserved. // # import "ViewController. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad];}-(void) touchesBegan :( NSSet <UITouch *> *) touches withEvent :( UIEvent *) event {// Add the status kCFRunLoopEntry = (1UL <0), kCFRunLoopBeforeTimers = (1UL <1 ), kCFRunLoopBeforeSources = (1UL <2), kCFRunLoopBeforeWaiting = (1UL <5), priority = (1UL <6), kCFRunLoopExit = (1UL <7), priority = 0x0FFFFFFFU */CFRunLoopObserverRef observe = timeout (CFAllocatorGetDefault (), kCFRunLoopAllActivities, YES, 0, ^ (CFRunLoopObserverRef observer, CFRunLoopActivity) {NSLog (@ "Listening to runloop -- % zd", activity );}); // Add the observer CFRunLoopAddObserver (CFRunLoopGetCurrent (), Observe, kCFRunLoopDefaultMode); // CF Core Foundation/* all objects created by functions with creat copy retain and other components must be released at the end, that is, Release. */CFRelease (observe);} @ end

The above is a simple supplement to CFRunLoopObserverRef.

Here we will briefly introduce the processing logic of RunLoop.

Runloop processing logic:

1. Notify the Observer to enter the loop.

2. Notify Observer to process timer

3. Notify Observer to process Source0

4. Process Source0

5. If Source1 exists, skip to step 1.

6. Notify the Obesrcer that the thread is about to sleep.

7. Sleep, waiting to wake up

8. Notify the Observer that the thread has just been awakened.

9. process the message received during wake-up and then jump back to 2.

10. Notify Oberver that the Loop is about to exit.

 

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.