Ios-nsthread use

Source: Internet
Author: User

Nsthread:

Pros: Nsthread two lighter than others (Cocoa nsoperation, GCD)

Cons: You need to manage your thread's life cycle, thread synchronization. Thread synchronization has a certain overhead in locking data

Cocoa operation

Pros: No need to care about thread management, data synchronization, you can focus on what you need to do.

Cocoa operation related classes are nsoperation, Nsoperationqueue. Nsoperation is an abstract class that uses its subclasses to implement it or to use the two subclasses it defines: Nsinvocationoperation and nsblockoperation. Creates an object of the Nsoperation subclass and adds the object to the Nsoperationqueue queue for execution.

GCD

Grand Central Dispatch (GCD) is a solution for multi-core programming developed by Apple. Can only be used after the iOS4.0 has started. GCD is an efficient and powerful alternative to technologies such as Nsthread, Nsoperationqueue, and Nsinvocationoperation. Now the iOS system has been upgraded to 6, so don't worry about the technology being used.

1. Nsthread has two direct creation methods:

-(ID) Initwithtarget: (ID) Target selector: (SEL) Selector object: (ID) argument

+ (void) Detachnewthreadselector: (SEL) Aselector totarget: (ID) atarget withobject: (ID) anargument

The first is an instance method, the second is a class method

2. The meaning of the parameter:

Selector: The method that the thread executes, this selector can only have one parameter, and cannot have the return value.

Target:selector object sent by message

Argument: The only parameter transmitted to target, or nil

The first way is to create the thread directly and start running the thread, the second way is to create the thread object before running the thread operation, you can set the thread's priority and so on thread information before running the thread operation

Ios-nsthread use

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.