Last active
March 8, 2017 15:20
-
-
Save sgr-ksmt/ad18552081839cf4f93e0c49aa56761e 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
class Hoge { | |
var a: String? { | |
didSet { | |
b = a | |
} | |
} | |
var b: String? | |
deinit { | |
print("\(#function)") | |
a = nil // これ | |
output() | |
} | |
func output() { | |
print("a:", a as Any) | |
print("b:", b as Any) | |
} | |
} | |
do { | |
let h = Hoge() | |
h.a = "Hoge" | |
h.output() | |
print("===") | |
h.a = nil | |
h.output() | |
print("===") | |
h.a = "Fuga" | |
h.output() | |
} | |
//============ | |
// didSet!! | |
// a: Optional("Hoge") | |
// b: Optional("Hoge") | |
// === | |
// didSet!! | |
// a: nil | |
// b: nil | |
// === | |
// didSet!! | |
// a: Optional("Fuga") | |
// b: Optional("Fuga") | |
// deinit | |
// a: nil | |
// b: Optional("Fuga") // !!!!!!! |
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
``swift | |
class Hoge { | |
var a: String? { | |
didSet { | |
print("didSet!!") | |
b = a | |
} | |
} | |
var b: String? | |
deinit { | |
defer { | |
print("\(#function)") | |
a = nil | |
output() | |
} | |
} | |
func output() { | |
print("a:", a as Any) | |
print("b:", b as Any) | |
} | |
} | |
do { | |
let h = Hoge() | |
h.a = "Hoge" | |
h.output() | |
print("===") | |
h.a = nil | |
h.output() | |
print("===") | |
h.a = "Fuga" | |
h.output() | |
} | |
// ================== | |
// didSet!! | |
// a: Optional("Hoge") | |
// b: Optional("Hoge") | |
// === | |
// didSet!! | |
// a: nil | |
// b: nil | |
// === | |
// didSet!! | |
// a: Optional("Fuga") | |
// b: Optional("Fuga") | |
// deinit | |
// didSet!! | |
// a: nil | |
// b: nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment