Skip to content

Instantly share code, notes, and snippets.

@TuenTuenna
Last active September 3, 2021 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TuenTuenna/34410fd612914719fd0f496e7b895eb9 to your computer and use it in GitHub Desktop.
Save TuenTuenna/34410fd612914719fd0f496e7b895eb9 to your computer and use it in GitHub Desktop.
Obj-C 매개변수를 가지는 컴플레션 블럭

Obj-c 매개변수를 가지는 컴플레션 블럭

//
//  ViewController.m
//  Obj-C_tutorial
//
//  Created by Jeff Jeong on 2021/01/04.
//

#import "ViewController.h"

@interface ViewController ()
@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSLog(@"ViewController - viewDidLoad() called");
    
    // 컴플레션 블럭 호출부
    [self myCompletionBlock:^(NSString *value) {
        NSLog(@"myCompletionBlock 이 호출됨 : %@", value);
    }];
}
// 매개변수로 문자열을 가지는 컴플레션 블럭 메소드 정의
- (void)myCompletionBlock:(void (^)(NSString *someNiceText))comepletion {
    if (comepletion) { // 블럭이 있으면
        // 블럭을 문자열과 함께 발동시킨다.
        comepletion(@"호호호호");
    }
}

@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment