IOS线程的四种方法

来源:互联网 发布:龙游天下丁五味知真相 编辑:程序博客网 时间:2024/06/06 04:52

第一种:NSThread

    NSThread *thread=[[NSThreadalloc]initWithTarget:selfselector:@selector(runningTap:)object:nil];

    [thread setName:@"窗口2"];

    [thread start];//手动启动线程

第二种:NSOperation

   NSInvocationOperation *io=[[NSInvocationOperationalloc]initWithTarget:selfselector:@selector(operationTap:)object:@"me"];

    //[io start];

    //操作线程队列队列中有线程池

    NSOperationQueue *queue=[[NSOperationQueuealloc]init];

    [queue addOperation:io];


第三种:GCD(提倡)

dispatch_async(dispatch_get_global_queue(0,0), ^(block));

第四种:

[self performSelectorOnMainThread:@selector() withObject:@"" waitUntilDone:YES];

0 0