iOS thread dependent

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.