The role of dependency: in iOS development, we often use a thread that needs to wait for another end to take place, a requirement that actually has a practical solution. Here are some of the methods that are currently used:
Requirements:: With nsopertion and nsopertionqueue processing a,b,c,d,e three threads, required to execute after a,b,d,e to execute C, how to do?
Create a queue
Nsoperationqueue *queue = [[Nsoperationqueue alloc] init];
Create 5 actions
Nsoperation *a = [Nsblockoperation blockoperationwithblock:^{
NSLog (@ "Operation---a");
}];
Nsoperation *b = [Nsblockoperation blockoperationwithblock:^{
NSLog (@ "Operation---b");
}];
Nsoperation *c = [Nsblockoperation blockoperationwithblock:^{
NSLog (@ "**************c");
}];
Nsoperation *d = [Nsblockoperation blockoperationwithblock:^{
NSLog (@ "Operation---d");
}];
Nsoperation *e = [Nsblockoperation blockoperationwithblock:^{
NSLog (@ "Operation---e");
}];
Add dependency
[C Adddependency:a];
[C ADDDEPENDENCY:B];
[C Adddependency:d];
[C Adddependency:e];
Perform actions
[Queue addoperation:a];
[Queue addoperation:b];
[Queue addoperation:c];
[Queue addoperation:d];
[Queue addoperation:e];
Printing results:
2017-08-17 18:38:02.040 Dependency [11633:750843] Operation---A
2017-08-17 18:38:02.040 Dependency [11633:757610] operation---b
2017-08-17 18:38:02.040 Dependency [11633:757611] operation---D
2017-08-17 18:38:02.040 Dependence [11633:757612] Operation---E
2017-08-17 18:38:02.042 dependence [11633:757610] **************c
iOS Thread dependency