网络多线程-NSOperation的简单使用
来源:互联网 发布:七五事件汉人反击 知乎 编辑:程序博客网 时间:2024/05/18 03:58
import "ViewController.h"
#import "XMGOperation.h"
@interface ViewController ()
@end
@implementation ViewController
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[selfcustomOperation];
}
-(void)customOperation
{
NSLog(@"-----");
//1.封装操作
XMGOperation *op1 = [[XMGOperationalloc]init];
XMGOperation *op2 = [[XMGOperationalloc]init];
//2.启动执行
[op1 start];
[op2 start];
}
-(void)invocationOperation
{
//1.封装操作
/*
第一个参数:目标对象SELF
第二个参数:要调用的是哪个方法
第三个参数:方法的参数
*/
NSInvocationOperation *op1 = [[NSInvocationOperationalloc]initWithTarget:selfselector:@selector(run)object:nil];
//2.启动执行操作
[op1 start];
NSInvocationOperation *op2 = [[NSInvocationOperationalloc]initWithTarget:selfselector:@selector(run)object:nil];
//2.启动执行操作
[op2 start];
NSInvocationOperation *op3 = [[NSInvocationOperationalloc]initWithTarget:selfselector:@selector(run)object:nil];
//2.启动执行操作
[op3 start];
}
-(void)blockOperation
{
//1.封装操作
NSBlockOperation *op1 = [NSBlockOperationblockOperationWithBlock:^{
//主线程
NSLog(@"1---%@",[NSThreadcurrentThread]);
}];
NSBlockOperation *op2 = [NSBlockOperationblockOperationWithBlock:^{
NSLog(@"2---%@",[NSThreadcurrentThread]);
}];
NSBlockOperation *op3 = [NSBlockOperationblockOperationWithBlock:^{
NSLog(@"3---%@",[NSThreadcurrentThread]);
}];
//添加额外任务
[op3 addExecutionBlock:^{
//子线程
NSLog(@"4---%@",[NSThreadcurrentThread]);
}];
[op3 addExecutionBlock:^{
NSLog(@"5---%@",[NSThreadcurrentThread]);
}];
//2.启动执行操作
[op1 start];
[op2 start];
[op3 start];
}
-(void)run
{
NSLog(@"run---%@",[NSThreadcurrentThread]);
}
@end
- 网络多线程-NSOperation的简单使用
- 多线程之NSOperation的简单使用
- NSOperation多线程的使用
- NSOperation的简单使用
- [第2章]多线程:NSOperation的简单使用
- iOS多线程NSOperation的使用
- 多线程:NSOperation 的基本使用
- 多线程:NSOperation 的依赖使用
- 多线程:NSOperation 的基本使用
- 网络多线程-NSOperation的常用的方法
- NSOperation的简单使用代码
- iOS多线程简介 - Swift版本 2.多线程开发 -- NSOperation的简单使用
- iOS 多线程 NSOperation的简单使用——iOS 编码复习(八)(多线程6)
- 多线程的使用(2) - NSOperation和NSOperationQueue
- iOS多线程 NSOperation和NSOperationQueue的使用
- 多线程的使用(2) - NSOperation和NSOperationQueue
- 多线程 - 10.NSOperation的使用示例
- NSOperation多线程的使用与理解
- FileTool.exe 替换 Visual C++ 的"打开"和"添加到项目中"的功能
- hdoj--5562--Clarke and food(模拟)
- android上不错的开源库及控件(持续更新)
- 排列宝石问题
- swift 中字符串比较
- 网络多线程-NSOperation的简单使用
- [POJ]2299 Ultra-QuickSort
- 数据结构实验之串一:KMP简单应用
- OC中关于数组的介绍
- UART与USART(转)
- 线索二叉树的实现
- 位运算(一)
- Android学习之PhotoView在Eclipse上的使用
- 如何使用正则表达式