LoginSignup
6
6

More than 5 years have passed since last update.

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

Last updated at Posted at 2013-08-07

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) {

    }];
6
6
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6