「Objective-C」ios開発でマルチスレッドを作成する方法のまとめ

方法1
NSThread * thread=[[NSThread alloc] initWithTarget:self selector:@selector(_update) object:nil];

方法2
[NSThread detachNewThreadSelector:@selector(_update) toTarget:self withObject:nil];

方法3
[self performSelectorInBackground:@selector(_update) withObject:nil];

方法4
NSOperationQueue *queue=[[NSOperationQueue alloc] init];
[queue addOperationWithBlock:^{
for(int i=0;i<50;i++){
printf(“child thread\n");
}
}];

方法5
NSOperationQueue * queue=[[NSOperationQueue alloc] init];
[queue setMaxConcurrentOperationCount:2];

NSInvocationOperation * thread1=[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(_update1) object:nil];
NSInvocationOperation *thread2=[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(_update2) object:nil];

[thread1 setQueuePriority:NSOperationQueuePriorityVeryLow];
[thread2 setQueuePriority:NSOperationQueuePriorityVeryHigh];

[queue addOperation:thread1];
[queue addOperation:thread2];

IOS

Posted by arkgame