반응형
var closureArray: [(Int) -> ()] = []
func asyncEscapingClosure( param1: Int, completion: @escaping (Int) -> () ) {
closureArray.append(completion)
DispatchQueue.main.async {
completion(param1)
}
print("asyncEscapingClosure 실행")
print("asyncEscapingClosure 중간부")
}
asyncEscapingClosure(param1: 7) { element in
print("넘겨받은 element: \(element)")
print("completion 클로저가 실행되었습니다.")
}
closureArray.first?(5)
closureArray.first?(5)
closureArray.first?(5)
closureArray.first?(5)
closureArray.first?(5)
closureArray.first?(5)
반응형
'Swift 문법' 카테고리의 다른 글
swift weak, unowned, delegate weak (0) | 2021.07.05 |
---|---|
Swift 튜플 (0) | 2021.03.11 |
Swift 에러처리 try do catch (0) | 2021.02.14 |
Swift protocol extension 프로토콜 익스텐션 (0) | 2021.02.08 |
swift guard let 사용하는 경우 (0) | 2020.11.17 |