iOS学习总结之多线程编程(NSThread)
来源:互联网 发布:淘宝印象笔记 编辑:程序博客网 时间:2024/05/16 19:03
这一久正在学习多线程编程,现在将自己学习总结跟大家分享一下
iOS提供了如下3种多线程编程的技术
>使用NSThread实现多线程
>使用NSOperation与NSOperationQueue实现多线程
>使用GCD(Grand Central Dispatch)实现多线程
这三种编程方式从上到下 抽象度层次是从低到高的 抽象度越高的用法越简单
- (void)viewDidLoad { [super viewDidLoad]; #pragma mark-使用NSThread实现多线程// 创建和启动线程// 创建NSthread有两种方式// >initWithTarget:<#(id)#> selector:<#(SEL)#> object:<#(id)#> 只创建需要手动启动// >detachNewThreadSelector:<#(SEL)#> toTarget:<#(id)#> withObject:<#(id)#> 创建并启动 for (int i = 0; i < 30; i ++) { NSLog(@"===%@===%i", [NSThread currentThread], i); if (i == 20) {// 创建线程对象 NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(run) object:nil];// 启动新线程 [thread start]; // 创建并启动新线程// [NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil]; } } }- (void)run{ for (int i = 0; i < 30; i++) {// [NSThread currentThread] 当前线程// 可以通过setName:方法为线程设置名字 也可以通过name方法返回指定线程的名字 NSLog(@"---%@---%i", [NSThread currentThread], i); }}
0 0
- iOS学习总结之多线程编程(NSThread)
- iOS学习总结之多线程编程(NSThread)-线程的状态
- IOS疯狂基础之多线程编程NSThread
- iOS 之多线程 NSThread
- 深入浅出 iOS 之多线程 NSThread
- 深入浅出 iOS 之多线程 NSThread
- 深入浅出 iOS 之多线程 NSThread
- 深入浅出 iOS 之多线程 NSThread
- 深入浅出 iOS 之多线程 NSThread
- 深入浅出 iOS 之多线程 NSThread
- 深入浅出 iOS 之多线程 NSThread
- 深入浅出 iOS 之多线程 NSThread
- iOS开发之多线程NSThread
- 深入浅出 iOS 之多线程 NSThread
- ios开发之多线程NSThread
- ios学习--深入浅出 iOS 之多线程 NSThread (转)
- iOS学习总结之多线程编程NSOperation & NSOperationQueue
- [iOS]深入浅出 iOS 之多线程 NSThread
- linux 的shell处理两Excel的比较方法
- javascript的一些常用正则表达式
- redhat下安装chrome
- 计算机辅助设计与图形学学术年会三十周年纪念感言
- poj 2375 Cow Ski Area 【SCC缩点 求最少增加几条边使图强连通】
- iOS学习总结之多线程编程(NSThread)
- 冒泡排序、归并排序、快速排序、堆排序
- 好好学习中。。。。
- 解递归式的方法
- 学习Javamail总结
- 单链表的基本操作(2)
- UIday05:target/action设计模式 代理设计模式 UIImageView ⼿势识别器
- JAVA问题总结之20--可变长度形参
- java IO流文件的读写具体实例