zoukankan      html  css  js  c++  java
  • NSRunLoop 的那些事--持续更新

      本文主要介绍NSRunLoop概念、特性及其应用。

      一、NSRunLoop是什么、有什么用?

        我们先看官方定义:

        “The NSRunLoop class declares the programmatic interface to objects that manage input sources. An NSRunLoop object processes input for sources such as mouse and keyboard events from the window system, NSPort objects, and NSConnection objects. An NSRunLoop object also processes NSTimer events.”

        NSRunLoop类型是用来管理输入源的。一个NSRunLoop对象会处理自来鼠标,键盘,NSPort对象和NSConnetion对象输入(传入)的事件,当然也处理NSTimer的事件。

        一句话,NSRunLoop是用来处理事件的类。

        每个线程都有一个自己的NSRunLoop对象,所以,我们不用去创建NSRunLoop对象,如果需要使用,使用  currentRunLoop方法  获取NSRunLoop对象即可。

      二、NSRunLoop什么时候用

        一般来说,以下四种情况会用到NSRunLoop,

    (一)Use ports or custom input sources to communicate with other threads. 

          使用端口或自定义的输入源与其他线程交互。

    (二)Use timers on the thread. 

      在线程中使用定时器。

    (三)Use any of the performSelector… methods in a Cocoa application. 

      使用任何performSelector开头的方法。

    (四)Keep the thread around to perform periodic tasks.

      在线程中执行周期性任务。

      

      三、NSRunLoop怎么用

        其实,我们经常在使用定时器的时候用到NSRunloop。

  • 相关阅读:
    zabbix监控
    ipv4固定ip地址
    CentOS7 内核优化 修改参数
    流媒体服务器 red5
    linux安装git
    zabbix-钉钉报警媒介
    Windows下利用IIS建立网站并实现局域网共享
    docker的简单操作和端口映射
    docker概述和安装及基本操作
    VMware Workstation创建Windows2012server虚拟机
  • 原文地址:https://www.cnblogs.com/panyuluoye/p/4934007.html
Copyright © 2011-2022 走看看