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。

  • 相关阅读:
    oracle 函数WMSYS.WM_CONCAT()的用法(行转列) 老猫
    PL/SQL 数独 九宫图 老猫
    oracle10g rman backup and recover 老猫
    Oracle SQL的优化 老猫
    Oracle数据库中的字符处理技巧总结 老猫
    WITH分析函数 老猫
    30套JSP网站源代码合集
    Java获取系统信息(cpu,内存,硬盘,进程等)的相关方法
    [原]Web Service学习
    常用Web Service汇总(天气预报、时刻表等)
  • 原文地址:https://www.cnblogs.com/panyuluoye/p/4934007.html
Copyright © 2011-2022 走看看