zoukankan      html  css  js  c++  java
  • ObjectiveC基础语法之NSRunLoop

    不进行讲解,直接上代码。

    1 #import <Foundation/Foundation.h>
    2 
    3 @interface Demo01 : NSObject
    4 
    5 
    6 -(void) run;
    7 -(void) start;
    8 
    9 @end
     1 #import "Demo01.h"
     2 
     3 @implementation Demo01
     4 
     5 -(void) run
     6 {
     7     static int counter = 0;
     8     
     9     while(![[NSThread currentThread]isCancelled]){
    10         [NSThread sleepForTimeInterval:1];
    11         NSLog(@"当前数值:%i",counter++);
    12     }
    13     
    14 }
    15 
    16 -(void) start
    17 {
    18     [NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil];
    19 }
    20 
    21 @end
     1 #import <Foundation/Foundation.h>
     2 #import "Demo01.h"
     3 
     4 int main(int argc, const char * argv[])
     5 {
     6 
     7     @autoreleasepool {
     8         
     9         // insert code here...
    10         NSLog(@"Hello, World!");
    11         
    12         [[[Demo01 alloc] init]start];
    13         
    14         while (YES) {
    15             
    16             [[NSRunLoop currentRunLoop]runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
    17         }
    18         
    19     }
    20     return 0;
    21 }
  • 相关阅读:
    awk
    Python自动化开发之python的常用模块
    sed
    python自动化开发-8
    正则表达式-2-正则表达式实战1
    linux之sort和uniq
    SSH免密登录
    Docker下安装Mongodb
    Docker下安装Elasticsearch
    Docker下安装RabbitMQ
  • 原文地址:https://www.cnblogs.com/xinye/p/3073495.html
Copyright © 2011-2022 走看看