iOS开发中的多线程
来源:互联网 发布:网络营销软件有哪些 编辑:程序博客网 时间:2024/06/11 20:47
最近整理了一下iOS开发中常用的几种多线程 // 第一种方式```NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(mutableThread) object:@"test"]; [thread start];``` // 第二种方式```[NSThread detachNewThreadSelector:@selector(mutableThread) toTarget:self withObject:nil];``` // 第三种方式```[self performSelectorInBackground:@selector(mutableThread) withObject:nil];``` // 第四种方式```NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init]; [operationQueue addOperationWithBlock:^{ // 多线程上执行的方法 }];``` // 第五种方式线程队列可以同时添加多个线程 可以设置优先级等``` NSOperationQueue *threadQueue = [[NSOperationQueue alloc] init]; NSInvocationOperation *op1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(mutableThread) object:nil]; NSInvocationOperation *op2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(mutableThread) object:nil]; [threadQueue addOperation:op1]; [threadQueue addOperation:op2];``` // 第六种方式 GCD 这个性能最好 推荐使用这个``` dispatch_queue_create("test", NULL); dispatch_async(queue, ^{ // 多线程 // 回到主线程执行 dispatch_sync(dispatch_get_main_queue(), ^{ 这里写代码片// 主线程操作的代码 }); }); return YES; }```// 多线程执行的方法注意!这边需要有一个自动释放池```- (void)mutableThread { @autoreleasepool { [self performSelectorOnMainThread:@selector(mainThread) withObject:nil waitUntilDone:NO];} }``` // 主线程```- (void)mianThread { }```
0 0
- ios 开发中的多线程
- ios 开发中的多线程
- iOS开发中的多线程
- iOS开发 中的 多线程
- UIday2201:IOS开发中的多线程
- 多线程技术在iOS开发中的使用
- iOS开发中的gcd多线程tips
- 多线程技术在iOS开发中的使用
- iOS开发中的gcd多线程tips
- iOS开发中的多线程的GCD用法
- iOS-----IOS多线程开发
- iOS开发多线程在实际项目中的运用
- iOS开发多线程在实际项目中的运用
- ios-多线程技术在开发中的应用场景
- iOS中的多线程
- IOS中的多线程
- iOS 中的多线程总结
- iOS中的多线程
- first Missing Positive number
- IOS缓存基本知识和清除缓存的方法
- mapreduce编程:求平均值
- QueryBuilder: A Simple Way to Read and Write Query Strings
- highCharts+ajax+json+ashx混合图形动态生成
- iOS开发中的多线程
- android设备判断网络连接状态
- JS解析json数据[转]
- vs自动注释add-in插件编写(一)--辅助函数
- 如何本地调试微信接口
- extern "C"的用法解析
- 判断文件夹是否存在,不存在创建文件夹
- LRM-00109: could not open parameter file
- Scala类继承与单例对象