Edited at

iOS メソッドの引数でBlocksを使う方法

More than 5 years have passed since last update.


typedef void (^TestMethodBlock)(BOOL arg1, BOOL arg2);

- (void)testMethodWithCompletion:(TestMethodBlock)_completion {

TestMethodBlock completion = [_completion copy];

// 別スレッド
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{

/// 時間のかかる処理 ///

// メインスレッド
dispatch_sync(dispatch_get_main_queue(), ^{
completion(YES, YES);
});
});
}

呼び出

    [self testMethodWithCompletion:^(BOOL arg1, BOOL arg2) {

}];