In most cases, injecting these values via init
is the preferred way.
For example:
class Foo
{
var x : String
convenience init()
{
self.init(x: "x") // 'x' by default
}
init(x: String)
{
self.x = x
}
}
class Bar : Foo
{
convenience init()
{
self.init(x: "y") // now 'y' by default
}
init(x: String)
{
super.init(x: x)
}
}
However, there are some cases where you want to override a computed property or perhaps something that is not exactly initialized.
In this case, you can use the override var
syntax:
override var x : String
{
get { return super.x } // get super.x value
set { super.x = newValue } // set super.x value
}
The above code does not change the behavior, but illustrates the syntax that would allow you to do so.