Created
June 28, 2017 20:47
-
-
Save efremidze/cbf45c900ea161c47ba3886ee468cc43 to your computer and use it in GitHub Desktop.
Forces didSet to get called on init
This file contains hidden or 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
import Foundation | |
class Object<Type> { | |
var value: Type! { | |
didSet { | |
print(value) | |
} | |
} | |
// init(_ value: Type) { | |
// self.value = value // didSet not called | |
// } | |
init(_ value: Type) { | |
defer { | |
self.value = value // didSet called | |
} | |
} | |
} | |
let object = Object("hello") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment