I am new to Swift and just came across this in the documentation:
Computed properties are provided by classes, structures, and enumerations. Stored
I use a small trick to store properties that are not accesible on initialization.
First, I create a class Future which will store the stored property in the future:
class Future {
var value: T?
init(value: T? = nil) {
self.value = value
}
}
Then I create my enum:
enum Sample {
case Test(future: Future)
}
Instantiate:
let enumTest = Sample.Test(future: Future())
Later in the code:
switch enumTest {
case let .Test(future):
future.value = "Foo"
}
And later on, you can access the value:
switch enumTest {
case let .Test(future):
// it will print Optional("Foo")
print("\(future.value)")
}
This is not something you should abuse, but it can be helpful in some cases.
Hope it helps.