1、循环
#import "ViewController.h"
@interface ViewController ()
{
dispatch_queue_t _messageQueue;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_messageQueue = dispatch_queue_create("son_thread", NULL);
for (int i = 0; i < 5; i++) {
[self test];
}
}
- (void)test {
dispatch_async(_messageQueue, ^{
NSLog(@"son_thread");
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"main_thread");
});
});
}
打印结果如下
本文通过一个具体的Objective-C代码示例介绍了如何使用GCD(Grand Central Dispatch)进行循环任务调度,创建子线程并回到主线程执行任务。
1万+

被折叠的 条评论
为什么被折叠?



