Skip to content

Instantly share code, notes, and snippets.

@efremidze
Created June 28, 2017 20:47
Show Gist options
  • Save efremidze/cbf45c900ea161c47ba3886ee468cc43 to your computer and use it in GitHub Desktop.
Save efremidze/cbf45c900ea161c47ba3886ee468cc43 to your computer and use it in GitHub Desktop.
Forces didSet to get called on init
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