An analysis of IOS Runloop three

Source: Internet
Author: User

After two introductions I would like to have a simple understanding of runloop, at least not ignorant.

In this article I would like to make a simple addition to "cfrunloopobserverref".

Let's talk about it before you add it.

Arc has rarely been seen in the current development.

But that's right with the OC object.

Cfrunloopobserverref belongs to CF (Core Foundation)

So we need to release it manually.

The rules are as follows:

Any function created with creat copy retain and other components must be released at the end, i.e. release.

////VIEWCONTROLLER.M//A brief analysis of CX Runloop////Created by Ma C on 16/3/29.//copyright©2016 year Xubaoaichiyu. All rights reserved.//#import "ViewController.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload];}-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event{    //Add observe    /*Monitored status Kcfrunloopentry = (1UL << 0), kcfrunloopbeforetimers = (1UL << 1), Kcfrunloopbeforesou     RCEs = (1UL << 2), kcfrunloopbeforewaiting = (1UL << 5), kcfrunloopafterwaiting = (1UL << 6), Kcfrunloopexit = (1UL << 7), kcfrunloopallactivities = 0x0fffffffu*/Cfrunloopobserverref Observe= Cfrunloopobservercreatewithhandler (Cfallocatorgetdefault (), Kcfrunloopallactivities, YES,0, ^(Cfrunloopobserverref Observer, cfrunloopactivity activity) {NSLog (@"The Superintendent hears runloop--%zd", activity);    }); //Add ObserverCfrunloopaddobserver (Cfrunloopgetcurrent (), observe, kcfrunloopdefaultmode); //CF Memory Management (Core Foundation)    /*any function created with creat copy retain and other components must be released at the end, i.e. release. */Cfrelease (observe);}@end

The above is a simple addition to cfrunloopobserverref.

Here is a brief introduction to Runloop's processing logic.

Runloop processing logic:

1, notify Observer, will enter loop

2, notify Observer, will handle timer

3, notify Observer, will deal with SOURCE0

4, Handling Source0

5, if there is a Source1, jump to the 9th step

6, notify Obesrcer, thread is about to hibernate

7, hibernate, waiting to wake up

8, notify Observer, Line Cheng Gang is awakened

9, processing the message received at wake-up, and then jumping back to 2

10, notify Oberver, will exit loop

An analysis of IOS Runloop three

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.