Skip to content

Instantly share code, notes, and snippets.

@cozzin
Created September 5, 2018 08:59
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 cozzin/6130197ead21efd90c74a58af147e395 to your computer and use it in GitHub Desktop.
Save cozzin/6130197ead21efd90c74a58af147e395 to your computer and use it in GitHub Desktop.
//: Playground - noun: a place where people can play
import UIKit
class TestClass {
deinit {
print("deinit \(self)")
}
var completion: ((UIButton) -> Void)?
/// 다음 오류로 인해, 옵셔널 파라메터는 이스케이핑인데, 어노테이션을 붙이면 에러남
/// 해당 클로저를 사용할 경우 반드시 weak를 사용해야 함
/// closure is already escaping in optional type argument
func something(completion: ((UIButton) -> Void)? = nil) {
// self.completion = completion
}
func execute() -> Void {
completion?(UIButton())
}
func test() {
something { /*[weak self]*/ button in
self.printButton(button)
}
}
func printButton(_ button: UIButton) {
print(button.description)
}
}
var aaa: TestClass? = TestClass()
aaa?.test()
aaa = nil
// x <@nonescaping> or <@escaping>
// o <@escaping> 필수
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment