美文网首页
多线程操作

多线程操作

作者: eryuxinling | 来源:发表于2016-08-13 17:56 被阅读8次
    /*
     第一个参数:目标对象 self
     第二个参数:方法选择器 调用的方法
     第三个参数:前面调用方法需要传递的参数 nil
     */
    // (第一种方法)1.创建线程
    NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(ran:) object:@"ABC"];
    // 2.启动线程
    [thread start];
    
    // (第二种方法)
    [NSThread detachNewThreadSelector:@selector(ran:) toTarget:self withObject:@"分离子线程"];
    
    // (第三种方法)
    [self performSelectorInBackground:@selector(ran:) withObject:@"开启后台线程"];
    
    线程间通信--png
    [self.imageView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:YES];
    
    // 计算一段代码的耗时时间
    NSDate *start = [NSDate date]; // 获得当前的时间
        
    NSDate *end = [NSDate date];
    NSLog(@"%f", [end timeIntervalSinceDate:start]);
    
    CFTimeInterval start = CFAbsoluteTimeGetCurrent();
    CFTimeInterval end = CFAbsoluteTimeGetCurrent();
    NSLog(@"%f", end - start);
    

    相关文章

      网友评论

          本文标题:多线程操作

          本文链接:https://www.haomeiwen.com/subject/knxysttx.html