I don't want to initialize a view controller until I need to display its view., so I have it in a lazy var like:
lazy var foo: NSViewController! = {
let foo = NSViewController()
foo.representedObject = self.representedObject
return foo
}()
// ...
override var representedObject: Any? {
didSet {
if foo != nil {
foo.representedObject = representedObject
}
}
}
self.representedObject
is set before foo
is ever referenced, but every time I call if foo != nil
, it initializes foo
:c
Is there any way I can test if foo
has already been set?
lazy var
has been referenced before? – Bettinabettine