Three methods for creating multithreading in iOS
(1) // use the NSObject method to create a thread// (This method will automatically open up a background thread, parameter 1: The method executed in this background thread, parameter 2: used to pass Parameters) [self defined mselectorinbackground: @ selector (banZhuanPlus) withObject: nil];
(2) // create a thread through NSThread (parameter 1: Method performer; parameter 2: method executed in the thread; parameter 3: used to pass Parameters)
// Step 1: Create a thread
NSThread * thread = [[NSThread alloc] initWithTarget: self selector: @ selector (banZhuanPlus) object: nil];
// Step 2: Execute
[Thread start];
[Thread release];
(3) // NSOperation is an operation unit used to execute methods. It is an abstract class and must be subclass or use the NSInvocationOperation or NSBlockOperation class created by the system)
//// NSOperation is the smallest operation unit and can be executed only once;
/// NSInvocationOperation Step 1: Create
NSInvocationOperation * invocation = [[NSInvocationOperation alloc] initWithTarget: self selector: @ selector (banZhuanPlus) object: nil];
/// Step 2: (if not set, do not add it to the queue)
// [Invocation start];
// NSBlockOperation Step 1: Create
NSBlockOperation * block = [NSBlockOperation blockOperationWithBlock: ^ {
[Self banZhuanPlus];
}];
/// Step 2: Execute (in the main thread)
// [Block start]; // if it is added to the queue, do not start
// This queue will automatically create an auxiliary thread for us
// Only NSOperation and subclass objects can be added to this queue;
NSOperationQueue * queue = [[NSOperationQueue alloc] init];
[Queue setMaxConcurrentOperationCount: 2]; // you can specify the maximum number of parallel rows;
[Queue addOperation: block]; // you only need to add the operation queue to the queue;
[Queue addOperation: invocation];
// Queue: FIFO
// Stack: Advanced and later
// The queue involves serial and parallel
// Serial: Only one task can be executed at a time.
// Parallel execution: multiple tasks can be executed at a time.
(When copying the whole part, note that there is no comment in the whole part)