[swift-evolution] [Proposal] Enums with static stored properties for each case
Brent Royal-Gordon
brent at architechies.com
Fri May 27 07:43:43 CDT 2016
> The suggested solution based on 'accessor' - will create assotiated properties each time the enum instace created, for each instance of enum type.
No; property accessors would be either computed or constant (so that all instances of a given case can share storage). This is much the way they would behave if they were included in behaviors.
You could write a property accessor with a setter, but it would have to be computed, and manipulate `self`'s cases and associated values:
enum Optional<T> {
accessor var unwrapped: T { get set }
case none {
unwrapped {
get { fatalError("No value") }
set { self = .some(newValue) }
}
}
case some (_ value: T) {
unwrapped {
get { return value }
set { self = .some(newValue) }
}
}
}
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list