<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><div><div style="font-family: Calibri,sans-serif; font-size: 11pt;">As I said before, I'm not in favour of this approach. And you completely missed my proposal in the alternatives.<br><br></div></div><div dir="ltr"><hr><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">From: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:janis.kirsteins@gmail.com">Jānis Kiršteins</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Sent: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">‎31/‎05/‎2016 11:17 AM</span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">To: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:me@lmpessoa.com">Leonardo Pessoa</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Cc: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:brent@architechies.com">Brent Royal-Gordon</a>; <a href="mailto:swift-evolution@swift.org">swift-evolution</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Subject: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">Re: [swift-evolution] [Proposal] Enums with static stored propertiesfor each case</span><br><br></div>I wrote a proposal draft:<br><br># Enum case stored properties<br><br>* Proposal: TBD<br>* Author: [Janis Kirsteins](https://github.com/kirsteins)<br>* Status: TBD<br>* Review manager: TBD<br><br>## Introduction<br><br>This proposal allows each enum case to have stored properties.<br><br>## Motivation<br><br>Enums cases can have a lot of constant (or variable) static values<br>associated with it. For example, planets can have mass, radius, age,<br>closest star etc. Currently there is no way to set or get those values<br>easily.<br><br>Example below shows that is hard to read and manage static associated<br>values with each case. It is hard to add or remove case as it would<br>require to add or remove code in four different places in file. Also<br>static associated value like `UIBezierPath` is recreated each time the<br>property is computed while it's constant.<br><br>```swift<br>enum Suit {<br>&nbsp;&nbsp;&nbsp; case spades<br>&nbsp;&nbsp;&nbsp; case hearts<br>&nbsp;&nbsp;&nbsp; case diamonds<br>&nbsp;&nbsp;&nbsp; case clubs<br><br>&nbsp;&nbsp;&nbsp; var simpleDescription: String {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch self {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .spades:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return "spades"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .hearts:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return "hearts"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .diamonds:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return "diamonds"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .clubs:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return "clubs"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; var color: UIColor {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch self {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .spades:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return .blackColor()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .hearts:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return .redColor()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .diamonds:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return .redColor()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .clubs:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return .blackColor()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; var symbol: String {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch self {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .spades:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return "♠"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .hearts:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return "♥"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .diamonds:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return "♦"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .clubs:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return "♣"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; var bezierPath: UIBezierPath {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch self {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .spades:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let path = UIBezierPath()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // omitted lines ...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return path<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .hearts:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let path = UIBezierPath()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // omitted lines ...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return path<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .diamonds:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let path = UIBezierPath()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // omitted lines ...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return path<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .clubs:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let path = UIBezierPath()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // omitted lines ...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return path<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>}<br>```<br><br>## Proposed solution<br><br>Support stored properties for enum cases just as each case were an<br>instance. Case properties are initialized block after each case<br>declaration.<br><br>```swift<br>enum Suit {<br>&nbsp;&nbsp;&nbsp; let simpleDescription: String<br>&nbsp;&nbsp;&nbsp; let color: UIColor<br>&nbsp;&nbsp;&nbsp; let symbol: String<br>&nbsp;&nbsp;&nbsp; let bezierPath: UIBezierPath<br><br>&nbsp;&nbsp;&nbsp; case spades {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; simpleDescription = "spades"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color = .blackColor()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; symbol = "♠"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let bezierPath = UIBezierPath()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // omitted lines ...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.bezierPath = bezierPath<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; case hearts {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; simpleDescription = "hearts"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color = .redColor()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; symbol = "♥"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let bezierPath = UIBezierPath()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // omitted lines ...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.bezierPath = bezierPath<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; case diamonds {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; simpleDescription = "diamonds"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color = .redColor()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; symbol = "♦"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let bezierPath = UIBezierPath()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // omitted lines ...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.bezierPath = bezierPath<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; case clubs {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; simpleDescription = "clubs"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color = .blackColor()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; symbol = "♣"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let bezierPath = UIBezierPath()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // omitted lines ...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.bezierPath = bezierPath<br>&nbsp;&nbsp;&nbsp; }<br>}<br><br>let symbol = Suit.spades.symbol // "♠"<br>```<br><br>The proposed solution improves:<br>- Readability as cases are closer with their related data;<br>- Improves code maintainability as a case can be removed or added in one place;<br>- Improved performance as there is no need to recreate static values;<br>- ~30% less lines of code in given example.<br><br>## Detailed design<br><br>#### Stored properties<br><br>Enum stored properties are supported the same way they are supported<br>for structs can classes. Unlike enum associated values, stored<br>properties are static to case and are shared for the same case.<br><br>Properties are accessed:<br>```swift<br>let simpleDescription = Suit.spades.simpleDescription<br>```<br><br>Mutable properties can be set:<br>```swift<br>Suit.spades.simpleDescription = "new simple description"<br>```<br><br>#### Initialization<br><br>If enum has uninitialized stored property it must be initialized in a<br>block after each case declaration. The block work the same way as<br>struct initialization. At the end of initialization block all<br>properties must be initialized.<br><br>```swift<br>enum Suit {<br>&nbsp;&nbsp;&nbsp; var simpleDescription: String<br><br>&nbsp;&nbsp;&nbsp; case spades {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; simpleDescription = "spades"<br>&nbsp;&nbsp;&nbsp; }<br>}<br>```<br><br>Initialization block can be combine with use of `rawValue`:<br><br>```swift<br>enum Suit: Int {<br>&nbsp;&nbsp;&nbsp; var simpleDescription: String<br><br>&nbsp;&nbsp;&nbsp; case spades = 1 {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; simpleDescription = "spades"<br>&nbsp;&nbsp;&nbsp; }<br>}<br>```<br>or associated values of the case:<br><br>```swift<br>enum Suit {<br>&nbsp;&nbsp;&nbsp; var simpleDescription: String<br><br>&nbsp;&nbsp;&nbsp; case spades(Int) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; simpleDescription = "spades"<br>&nbsp;&nbsp;&nbsp; }<br>}<br>```<br><br>## Impact on existing code<br><br>Stored properties for enums are not currently not supported, so there<br>is no impact on existing code.<br><br>## Alternatives considered<br><br>- Use labeled tuple as `rawValue` of the enum case. This approach is<br>not compatible as it conflicts with intention of `rawValue` of Swift<br>enum;<br>- Use per case initializer like [Java<br>Enum](https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html).<br>Swift enum uses custom initializer syntax to setup instances, not<br>cases. So this approach is not suitable for Swift.<br><br><br>On Sun, May 29, 2016 at 3:42 PM, Leonardo Pessoa &lt;me@lmpessoa.com&gt; wrote:<br>&gt; I think that's the case with enums. You're changing their current behaviour of only having stored values to one in which it's computed (even if only once and then stored). Enums are IMO something that have a static value you know beforehand and can count on. That's why I'm not fond of the accessor proposal. Otherwise I think we're transforming enums into a closed set of struct instances and one could do that already by using a private init.<br>&gt;<br>&gt;<br>&gt;&gt; On 29 May 2016, at 3:38 am, Jānis Kiršteins via swift-evolution &lt;swift-evolution@swift.org&gt; wrote:<br>&gt;&gt;<br>&gt;&gt; I agree with the argument about use of "where", not replacing the raw<br>&gt;&gt; value and having some kind of initialization block. But I cannot see<br>&gt;&gt; why "accessors" concept is any better than stored properties to solve<br>&gt;&gt; the particular problem. The "accessors" concept has much wider scope<br>&gt;&gt; than enums and is a separate proposal.<br>&gt;&gt;<br>&gt;&gt; On Sat, May 28, 2016 at 11:39 PM, Brent Royal-Gordon<br>&gt;&gt; &lt;brent@architechies.com&gt; wrote:<br>&gt;&gt;&gt;&gt;&gt; - Abusing rawValue is just that: an abuse.<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; My original proposal does not replace rawValue and is compatible with it.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; `rawValue` has a different purpose from how you're using it. It's supposed to allow you to convert your type to some other *equivalent* type, like an equivalent integer or string. Moreover, it's supposed to allow you to *reconstruct* the instance from the raw value—remember, `RawRepresentable` has an `init(rawValue:)` requirement.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; It is *not* supposed to be an ancillary bag of information on the side. You're cramming a square peg into a round hole here.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; (Also, if you use `rawValue` for an ancillary bag of information, that means you *can't* use it on the same type for its intended purpose. For instance, you would not be able to assign numbers to your Planet enum's cases to help you serialize them or bridge them to Objective-C. That's not good.)<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;&gt; - Using `where` just doesn't match the use of `where` elsewhere in the language; everywhere else, it's some kind of condition.<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; It is also used in generic type constraints. Plus it reads like human<br>&gt;&gt;&gt;&gt; language: `case mercury where (mass: 3.303e+23, radius: 2.4397e6)`<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; But a generic constraint is also a type of condition: it specifies types which are permitted and divides them from types that are not.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; This is *not* a condition. It's not anything like a condition. It's simply not consistent with anything else in the language.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;&gt; - Dictionaries are the most straightforward way to handle this with the current language, but their lack of exhaustiveness checking is a problem.<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Dictionaries can be used as workaround, but they cannot (lack of<br>&gt;&gt;&gt;&gt; exhaustiveness) solve the problem.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; I agree that they're a halfway solution.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; If `ValuesEnumerable` were to be accepted (and to have a generic requirement for its `allValues` property), you could write a Dictionary-like type which ensured at initialization time that it was exhaustive. That's not as good as compile time, but it's not bad—sort of a three-quarters solution.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct ExhaustiveDictionary&lt;Key: Hashable, Value where Key: ValuesEnumerable&gt;: Collection, DictionaryLiteralConvertible {<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private var dictionary: [Key: Value]<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; init(dictionaryLiteral elements: (Key, Value)...) {<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dictionary = [:]<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (k, v) in elements {<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dictionary[k] = v<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if dictionary.count != Key.allValues.count {<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let missingKeys = Key.allValues.filter { dictionary[$0] == nil }<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preconditionFailure("ExhaustiveDictionary is missing elements from \(Key.self): \(missingKeys)")<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var startIndex: Dictionary.Index {<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return dictionary.startIndex<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var endIndex: Dictionary.Index {<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return dictionary.endIndex<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; subscript(index: Dictionary.Index) -&gt; (Key, Value) {<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return dictionary[index]<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; func index(after i: Dictionary.Index) -&gt; Dictionary.Index {<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return dictionary.index(after: i)<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; subscript(key: Key) -&gt; Value {<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get { return dictionary[key]! }<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set { dictionary[key] = newValue }<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;&gt; What I would do is borrow the "accessors" concept from the property behaviors proposal and extend it so that it supported both functions and variables.<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Wouldn't accessor just be a redundant keyword here? Currently enums do<br>&gt;&gt;&gt;&gt; not support stored properties, so I guess there is no extra need to<br>&gt;&gt;&gt;&gt; mark properties with any special keyword.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; The keyword is mainly to indicate the unusual syntax at the definition site, where you only have to specify the name of the accessor you're defining, not a `func` or `var` keyword, a return type, or even parameter names. (Like `willSet`, there's a default parameter name you can use.) Secondarily, though, I think it's helpful to indicate very explicitly that this is not an ordinary method or property definition, even if the compiler could perhaps sort things out without it. `accessor` is something a user can Google if they've never seen it before.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Property accessors might work for enums with associated values, but<br>&gt;&gt;&gt;&gt; not so well without them.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; The two have nothing to do with each other. I showed your planets example, which has no associated values but uses accessors just fine.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; --<br>&gt;&gt;&gt; Brent Royal-Gordon<br>&gt;&gt;&gt; Architechies<br>&gt;&gt;&gt;<br>&gt;&gt; _______________________________________________<br>&gt;&gt; swift-evolution mailing list<br>&gt;&gt; swift-evolution@swift.org<br>&gt;&gt; https://lists.swift.org/mailman/listinfo/swift-evolution<br></body></html>