Created
December 11, 2018 20:51
-
-
Save TachibanaKaoru/fe0551e48fcd0eadc3e1ed19ec9c0078 to your computer and use it in GitHub Desktop.
Circular reference
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
class Person{ | |
var name: String | |
init(name: String) { | |
print("--- init \(name) ---") | |
self.name = name | |
} | |
deinit { | |
print("--- deinit \(name) ---") | |
} | |
func normalHello(){ | |
print("Hello, I am \(name)!") | |
} | |
// MARK: - Closure関連 | |
private var keepingClosure:(()->Void)? | |
private func keepAndDo(_ closure:@escaping (()-> Void)){ | |
self.keepingClosure = closure | |
closure() | |
} | |
// MARK: - Hello系 | |
func strongHello(){ | |
self.keepAndDo { | |
self.normalHello() | |
} | |
} | |
func weakHello(){ | |
self.keepAndDo { [weak self] in | |
self?.normalHello() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment