多线程操作

/*
 第一个参数:目标对象 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:@"开启后台线程"];
多线程操作_第1张图片
线程间通信--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);

你可能感兴趣的:(多线程操作)