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。

  • 相关阅读:
    PLC 输入输出接线示意图
    光耦的使用
    windows server 2008R2 搭建FTP服务器的步骤:
    C# semaphore的使用
    Multisim模拟 达灵顿管,防反接电路,恒流源电路
    一些芯片资料
    220V交流转5V直流电路详细
    STM32中的模拟IIC使用
    基于C8T6的DA14580蓝牙方案
    基本元件实验:继电器
  • 原文地址:https://www.cnblogs.com/panyuluoye/p/4934007.html
Copyright © 2011-2022 走看看