GCD->OC

VHAsyncRun.h

//
//  VHAsyncRun.h
//  VHUpload
//
//  Created by vhall on 2019/11/7.
//  Copyright © 2019 vhall. All rights reserved.
//

typedef void (^VHRun)(void);

void VHAsyncRun(VHRun run);

void VHAsyncRunInMain(VHRun run);

VHAsyncRun.m

//
//  VHAsyncRun.m
//  VHUpload
//
//  Created by vhall on 2019/11/7.
//  Copyright © 2019 vhall. All rights reserved.
//

#import "VHAsyncRun.h"
#import <Foundation/Foundation.h>

void VHAsyncRun(VHRun run) {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
        run();
    });
}

void VHAsyncRunInMain(VHRun run) {
    dispatch_async(dispatch_get_main_queue(), ^(void) {
        run();
    });
}

使用

VHAsyncRunInMain(^{
    
});
VHAsyncRun(^{
    
});

然并卵…

发布了131 篇原创文章 · 获赞 9 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/Morris_/article/details/102952125
gcd