IOS Multithreaded Learning Note--nsoperation

Source: Internet
Author: User

This article copies, references from the article: iOS multithreading programming nsoperation and Nsoperationqueue use, mainly in order to strengthen the personal understanding and memory of knowledge, do not do his use. Original Author statement:

Copyright statement: This article by http://blog.csdn.net/totogo2010/Original, welcome reprint share. Please respect the author Labor, reproduced when the statement and the author of the blog link, thank you!

Thanks for the hard work of the original author here!

1. There are two ways to use abstract nsoperation:

(1) Sub-classes defined with libraries: Nsinvocationoperation and Nsblockoperation.

(2) Custom class, inherit from Nsoperation. Like Java's runnable, Nsoperation is also designed to be extended by simply overriding the Nsoperation main method, which is equivalent to the Run method in Java. Then put the object of the Nsoperation subclass into the Nsoperationqueue queue, and the queue is enabled and starts processing it.

2. Example of using nsinvocationoperation: Loading pictures asynchronously

(1) Add multi-threaded calls in VIEWCONTROLLER.M:

-(void) viewdidload{    [Super Viewdidload];     // additional setup after loading the view, typically from a nib.    Object : Kurl];    Nsoperationqueue* queue = [[Nsoperationqueue alloc]init];    [Queue addoperation:operation];}

The other is consistent with the Nsthread example.

3. Examples of using custom classes

Replace the Nsinvocationoperation class in 2. With the custom Nsoperation subclass, and implement the Downloadimage method in the main method in the subclass.

IOS Multithreaded Learning Note--nsoperation

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.