iOS learning _nsoperationqueue and nsoperation learning notes

Source: Internet
Author: User

Steps to use:

(1) Encapsulating the tasks to be performed

(2) Create a queue

(3) Adding operations to the queue

Common methods for Queuing (Nsoperationqueue):

Cancel all operations: [Queue cancelalloperations];

Pause of queue: [Queue Setsuspended:yes]; Users can pause the download operation when they start scrolling

Queue recovery: [Queue Setsuspended:no]; The user starts to download the picture operation when it stops scrolling

Queues can also add actions directly: [Queue addoperationwithblock: ^{}];

Get the home row: [Nsoperationqueue mainqueue];

operation dependent: [Operationa adddependency:operationb];// You can create dependencies between different queue nsoperation, but you can't depend on each other .

Listening operation: Operation.completionblock = ^{};

Nsinvocationoperation is the same point as nsblockoperation:

(1) The no-add operation is not placed in the queue and is performed synchronously in the current thread.

(2) The Start method must be called to execute

(3) If you are adding to a queue, you do not have to call the Start method

Nsinvocationoperation and nsblockoperation different points :

(1) Nsblockoperation not placed in the queue can also be used to thread, using [Blockoperation addexecutionblock:^ (void) block]

Steps and notes for customizing Nsoperation:

(1) must implement the main function, in the main method to achieve the specific operation.

(2) Write a @autoreleasepool method inside the Main method

(3) When comparing time-consuming code, it is necessary to judge (iscancelled) if it has been canceled.

Related knowledge points and points of attention:

(1) nsoperation is an abstract class, does not have the ability to encapsulate operations, must be able to use its subclasses, must implement the Main method

(2) Nsoperation sub-class type: Nsblcokoperation, nsinvocationoperation, Custom (operation)

(3) Maximum number of concurrent Maxconcurrentoperationcount: The maximum number of thread operations opened, generally set to a few;

(4) It is best to determine if it is empty in the Insert dictionary

iOS learning _nsoperationqueue and nsoperation learning notes

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.