Created
September 5, 2018 08:59
-
-
Save cozzin/6130197ead21efd90c74a58af147e395 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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