# \[Discussion\] Enum Leading Dot Prefixes

**URL:** <https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404>\
**Category:** Discussion\
**Created:** [February 12, 2016, 3:00am UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404 "2016-02-12T03:00:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erica\_Sadun](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/erica_sadun/32/243_2.png) [@Erica\_Sadun](https://forums.swift.org/u/Erica_Sadun)\
**Post date:** [February 12, 2016, 3:00am UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/1 "2016-02-12T03:00:11Z")

</div>

> <https://gist.github.com/erica/e0b8a3a22ab716a19db4>

Requiring Leading Dot Prefixes for Enum Instance Member Implementations

Proposal: TBD  
Author(s): Erica Sadun \<[http://github.com/erica&gt;](http://github.com/erica&gt;), Chris Lattner \<[https://github.com/lattner&gt](https://github.com/lattner&gt);  
Status: TBD  
Review manager: TBD  
\<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#introduction&gt;Introduction)

Enumeration cases are essentially static not instance type members. Unlike static members in structures and classes, enumeration cases can be mentioned in initializers and instance methods without referencing a fully qualified type. This makes little sense. In no other case can an instance implementation directly access a static member. This proposal introduces a rule that requires leading dots or fully qualified references (EnumType.caseMember) to provide a more consistent developer experience to clearly disambiguate static cases from instance members.

\<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#motivation&gt;Motivation)

Swift infers the enclosing type for a case on a developer's behalf when the use is unambiguously of a single enumeration type. Inference enables you to craft switch statements like this:

switch Coin() {  
case .Heads: print("Heads")  
case .Tails: print("Tails")  
}  
A leading dot has become a conventional shorthand for "enumeration case" across the language. When used internally in enum implementations, a leading dot is not required, nor is a type name to access the static case member. The following code is legal in Swift.

enum Coin {  
&nbsp;&nbsp;&nbsp;&nbsp;case Heads, Tails  
&nbsp;&nbsp;&nbsp;&nbsp;func printMe() {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch self {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case Heads: print("Heads") // no leading dot  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Tails: print("Tails") // leading dot  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if self == Heads { // no leading dot  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("This is a head")  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if self == .Tails { // leading dot  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("This is a tail")  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;init() {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let cointoss = arc4random\_uniform(2) == 0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self = cointoss ? .Heads : Tails // mix and match leading dots  
&nbsp;&nbsp;&nbsp;&nbsp;}  
}  
This quirk produces a language inconsistency that can confuse developers and contravenes the guiding Principle of Least Astonishment. We propose to mandate a leading dot. This will bring case mentions into lock-step with the conventions used to reference them outside of enumeration type implementations.

\<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#detail-design&gt;Detail) Design

Under this rule, the compiler will require a leading dot for all case members. The change will not affect other static members, which require fully qualified references from instance methods and infer self from static methods.

enum Coin {  
&nbsp;&nbsp;&nbsp;&nbsp;case Heads, Tails  
&nbsp;&nbsp;&nbsp;&nbsp;static func doSomething() { print("Something") }  
&nbsp;&nbsp;&nbsp;&nbsp;static func staticFunc() { doSomething() } // does not require leading dot  
&nbsp;&nbsp;&nbsp;&nbsp;static func staticFunc2() { let foo = .Tails } // requires leading dot  
&nbsp;&nbsp;&nbsp;&nbsp;func instanceFunc() { self.dynamicType.doSomething() } // requires full qualification  
&nbsp;&nbsp;&nbsp;&nbsp;func otherFunc() { if self == .Heads ... } // requires leading dot, also initializers

&nbsp;&nbsp;&nbsp;&nbsp;/// ...  
}  
\<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#alternatives-considered&gt;Alternatives) Considered

Other than leaving the status quo, the language could force instance members to refer to cases using a fully qualified type, as with other static members.

---

<div class="post-metadata">

**Author:** ![Brent\_Royal-Gordon](https://avatars.discourse-cdn.com/v4/letter/b/53a042/32.png) [@Brent\_Royal-Gordon](https://forums.swift.org/u/Brent_Royal-Gordon)\
**Post date:** [February 12, 2016, 4:09am UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/2 "2016-02-12T04:09:00Z")

</div>

> [enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4)
> 
> Requiring Leading Dot Prefixes for Enum Instance Member Implementations
> 
> &nbsp;&nbsp;• Proposal: TBD  
> &nbsp;&nbsp;• Author(s): Erica Sadun, Chris Lattner  
> &nbsp;&nbsp;• Status: TBD  
> &nbsp;&nbsp;• Review manager: TBD

+1. I've always found this slightly bizarre.

I assume, though, that if you're writing a static member of an enum, the unprefixed form is fine?

> **···**
>
> --  
> Brent Royal-Gordon  
> Architechies

---

<div class="post-metadata">

**Author:** ![mayoff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mayoff/32/613_2.png) [@mayoff](https://forums.swift.org/u/mayoff)\
**Post date:** [February 12, 2016, 3:17am UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/3 "2016-02-12T03:17:20Z")

</div>

Why not go the other way then and allow instance methods to refer to static  
members (or class members) directly, without the type name prefix?

> **···**
>
> On Thu, Feb 11, 2016 at 9:00 PM, Erica Sadun via swift-evolution \< swift-evolution@swift.org\> wrote:
> 
> > Unlike static members in structures and classes, enumeration cases can be  
> > mentioned in initializers and instance methods without referencing a fully  
> > qualified type.

---

<div class="post-metadata">

**Author:** ![dabrahams](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dabrahams/32/9815_2.png) [@dabrahams](https://forums.swift.org/u/dabrahams)\
**Post date:** [February 12, 2016, 6:31am UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/4 "2016-02-12T06:31:52Z")

</div>

> [enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4)
> 
> Requiring Leading Dot Prefixes for Enum Instance Member Implementations
> 
> Proposal: TBD  
> Author(s): Erica Sadun \<[http://github.com/erica&gt;](http://github.com/erica&gt;), Chris Lattner \<[https://github.com/lattner&gt](https://github.com/lattner&gt);  
> Status: TBD  
> Review manager: TBD  
> \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#introduction&gt;Introduction)
> 
> Enumeration cases are essentially static not instance type members. Unlike static members in structures and classes, enumeration cases can be mentioned in initializers and instance methods without referencing a fully qualified type. This makes little sense. In no other case can an instance implementation directly access a static member. This proposal introduces a rule that requires leading dots or fully qualified references (EnumType.caseMember) to provide a more consistent developer experience to clearly disambiguate static cases from instance members.
> 
> \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#motivation&gt;Motivation)
> 
> Swift infers the enclosing type for a case on a developer's behalf when the use is unambiguously of a single enumeration type. Inference enables you to craft switch statements like this:
> 
> switch Coin() {  
> case .Heads: print("Heads")  
> case .Tails: print("Tails")  
> }

FYI, after considering the feedback here along with other factors, the  
API guidelines working group decided a few days ago to make enum cases  
lowerCamelCase like other values. Sorry I failed to announce that  
earlier.

> **···**
>
> on Thu Feb 11 2016, Erica Sadun \<swift-evolution@swift.org\> wrote:
> 
> > A leading dot has become a conventional shorthand for "enumeration case" across the language. When used internally in enum implementations, a leading dot is not required, nor is a type name to access the static case member. The following code is legal in Swift.
> > 
> > enum Coin {  
> > &nbsp;&nbsp;&nbsp;&nbsp;case Heads, Tails  
> > &nbsp;&nbsp;&nbsp;&nbsp;func printMe() {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch self {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case Heads: print("Heads") // no leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Tails: print("Tails") // leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if self == Heads { // no leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("This is a head")  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if self == .Tails { // leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("This is a tail")  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> > &nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;init() {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let cointoss = arc4random\_uniform(2) == 0  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self = cointoss ? .Heads : Tails // mix and match leading dots  
> > &nbsp;&nbsp;&nbsp;&nbsp;}  
> > }  
> > This quirk produces a language inconsistency that can confuse developers and contravenes the guiding Principle of Least Astonishment. We propose to mandate a leading dot. This will bring case mentions into lock-step with the conventions used to reference them outside of enumeration type implementations.
> > 
> > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#detail-design&gt;Detail) Design
> > 
> > Under this rule, the compiler will require a leading dot for all case members. The change will not affect other static members, which require fully qualified references from instance methods and infer self from static methods.
> > 
> > enum Coin {  
> > &nbsp;&nbsp;&nbsp;&nbsp;case Heads, Tails  
> > &nbsp;&nbsp;&nbsp;&nbsp;static func doSomething() { print("Something") }  
> > &nbsp;&nbsp;&nbsp;&nbsp;static func staticFunc() { doSomething() } // does not require leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;static func staticFunc2() { let foo = .Tails } // requires leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;func instanceFunc() { self.dynamicType.doSomething() } // requires full qualification  
> > &nbsp;&nbsp;&nbsp;&nbsp;func otherFunc() { if self == .Heads ... } // requires leading dot, also initializers
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;/// ...  
> > }  
> > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#alternatives-considered&gt;Alternatives) Considered
> > 
> > Other than leaving the status quo, the language could force instance members to refer to cases using a fully qualified type, as with other static members.  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)
> 
> --  
> -Dave

---

<div class="post-metadata">

**Author:** ![Carlos\_Parada](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@Carlos\_Parada](https://forums.swift.org/u/Carlos_Parada)\
**Post date:** [February 12, 2016, 6:41am UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/5 "2016-02-12T06:41:33Z")

</div>

Taking consistency further, should the definition also use dot prefixes? For example:

> enum Coin {  
> &nbsp;&nbsp;&nbsp;&nbsp;case .Heads, .Tails  
> &nbsp;&nbsp;&nbsp;&nbsp;func printMe() {  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch self {  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Heads: print("Heads")  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Tails: print("Tails")  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> &nbsp;&nbsp;&nbsp;&nbsp;}  
> }

— Carlos Parada

---

<div class="post-metadata">

**Author:** ![Daniel\_Steinberg](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/daniel_steinberg/32/334_2.png) [@Daniel\_Steinberg](https://forums.swift.org/u/Daniel_Steinberg)\
**Post date:** [February 12, 2016, 2:23pm UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/6 "2016-02-12T14:23:38Z")

</div>

+1 for consistency reasons

> **···**
>
> > On Feb 11, 2016, at 10:00 PM, Erica Sadun via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > [enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4)
> > 
> > Requiring Leading Dot Prefixes for Enum Instance Member Implementations
> > 
> > Proposal: TBD  
> > Author(s): Erica Sadun \<[http://github.com/erica&gt;](http://github.com/erica&gt;), Chris Lattner \<[https://github.com/lattner&gt](https://github.com/lattner&gt);  
> > Status: TBD  
> > Review manager: TBD  
> > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#introduction&gt;Introduction)
> > 
> > Enumeration cases are essentially static not instance type members. Unlike static members in structures and classes, enumeration cases can be mentioned in initializers and instance methods without referencing a fully qualified type. This makes little sense. In no other case can an instance implementation directly access a static member. This proposal introduces a rule that requires leading dots or fully qualified references (EnumType.caseMember) to provide a more consistent developer experience to clearly disambiguate static cases from instance members.
> > 
> > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#motivation&gt;Motivation)
> > 
> > Swift infers the enclosing type for a case on a developer's behalf when the use is unambiguously of a single enumeration type. Inference enables you to craft switch statements like this:
> > 
> > switch Coin() {  
> > case .Heads: print("Heads")  
> > case .Tails: print("Tails")  
> > }  
> > A leading dot has become a conventional shorthand for "enumeration case" across the language. When used internally in enum implementations, a leading dot is not required, nor is a type name to access the static case member. The following code is legal in Swift.
> > 
> > enum Coin {  
> > &nbsp;&nbsp;&nbsp;&nbsp;case Heads, Tails  
> > &nbsp;&nbsp;&nbsp;&nbsp;func printMe() {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch self {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case Heads: print("Heads") // no leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Tails: print("Tails") // leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if self == Heads { // no leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("This is a head")  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if self == .Tails { // leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("This is a tail")  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> > &nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;init() {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let cointoss = arc4random\_uniform(2) == 0  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self = cointoss ? .Heads : Tails // mix and match leading dots  
> > &nbsp;&nbsp;&nbsp;&nbsp;}  
> > }  
> > This quirk produces a language inconsistency that can confuse developers and contravenes the guiding Principle of Least Astonishment. We propose to mandate a leading dot. This will bring case mentions into lock-step with the conventions used to reference them outside of enumeration type implementations.
> > 
> > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#detail-design&gt;Detail) Design
> > 
> > Under this rule, the compiler will require a leading dot for all case members. The change will not affect other static members, which require fully qualified references from instance methods and infer self from static methods.
> > 
> > enum Coin {  
> > &nbsp;&nbsp;&nbsp;&nbsp;case Heads, Tails  
> > &nbsp;&nbsp;&nbsp;&nbsp;static func doSomething() { print("Something") }  
> > &nbsp;&nbsp;&nbsp;&nbsp;static func staticFunc() { doSomething() } // does not require leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;static func staticFunc2() { let foo = .Tails } // requires leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;func instanceFunc() { self.dynamicType.doSomething() } // requires full qualification  
> > &nbsp;&nbsp;&nbsp;&nbsp;func otherFunc() { if self == .Heads ... } // requires leading dot, also initializers
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;/// ...  
> > }  
> > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#alternatives-considered&gt;Alternatives) Considered
> > 
> > Other than leaving the status quo, the language could force instance members to refer to cases using a fully qualified type, as with other static members.  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

<div class="post-metadata">

**Author:** ![Patrick\_Gili](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/patrick_gili/32/6033_2.png) [@Patrick\_Gili](https://forums.swift.org/u/Patrick_Gili)\
**Post date:** [February 13, 2016, 5:02pm UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/7 "2016-02-13T17:02:35Z")

</div>

+1, as it adds consistency to the language.

> **···**
>
> > On Feb 11, 2016, at 10:00 PM, Erica Sadun via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > [enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4)
> > 
> > Requiring Leading Dot Prefixes for Enum Instance Member Implementations
> > 
> > Proposal: TBD  
> > Author(s): Erica Sadun \<[http://github.com/erica&gt;](http://github.com/erica&gt;), Chris Lattner \<[https://github.com/lattner&gt](https://github.com/lattner&gt);  
> > Status: TBD  
> > Review manager: TBD  
> > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#introduction&gt;Introduction)
> > 
> > Enumeration cases are essentially static not instance type members. Unlike static members in structures and classes, enumeration cases can be mentioned in initializers and instance methods without referencing a fully qualified type. This makes little sense. In no other case can an instance implementation directly access a static member. This proposal introduces a rule that requires leading dots or fully qualified references (EnumType.caseMember) to provide a more consistent developer experience to clearly disambiguate static cases from instance members.
> > 
> > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#motivation&gt;Motivation)
> > 
> > Swift infers the enclosing type for a case on a developer's behalf when the use is unambiguously of a single enumeration type. Inference enables you to craft switch statements like this:
> > 
> > switch Coin() {  
> > case .Heads: print("Heads")  
> > case .Tails: print("Tails")  
> > }  
> > A leading dot has become a conventional shorthand for "enumeration case" across the language. When used internally in enum implementations, a leading dot is not required, nor is a type name to access the static case member. The following code is legal in Swift.
> > 
> > enum Coin {  
> > &nbsp;&nbsp;&nbsp;&nbsp;case Heads, Tails  
> > &nbsp;&nbsp;&nbsp;&nbsp;func printMe() {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch self {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case Heads: print("Heads") // no leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Tails: print("Tails") // leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if self == Heads { // no leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("This is a head")  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if self == .Tails { // leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("This is a tail")  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> > &nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;init() {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let cointoss = arc4random\_uniform(2) == 0  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self = cointoss ? .Heads : Tails // mix and match leading dots  
> > &nbsp;&nbsp;&nbsp;&nbsp;}  
> > }  
> > This quirk produces a language inconsistency that can confuse developers and contravenes the guiding Principle of Least Astonishment. We propose to mandate a leading dot. This will bring case mentions into lock-step with the conventions used to reference them outside of enumeration type implementations.
> > 
> > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#detail-design&gt;Detail) Design
> > 
> > Under this rule, the compiler will require a leading dot for all case members. The change will not affect other static members, which require fully qualified references from instance methods and infer self from static methods.
> > 
> > enum Coin {  
> > &nbsp;&nbsp;&nbsp;&nbsp;case Heads, Tails  
> > &nbsp;&nbsp;&nbsp;&nbsp;static func doSomething() { print("Something") }  
> > &nbsp;&nbsp;&nbsp;&nbsp;static func staticFunc() { doSomething() } // does not require leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;static func staticFunc2() { let foo = .Tails } // requires leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;func instanceFunc() { self.dynamicType.doSomething() } // requires full qualification  
> > &nbsp;&nbsp;&nbsp;&nbsp;func otherFunc() { if self == .Heads ... } // requires leading dot, also initializers
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;/// ...  
> > }  
> > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#alternatives-considered&gt;Alternatives) Considered
> > 
> > Other than leaving the status quo, the language could force instance members to refer to cases using a fully qualified type, as with other static members.  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

<div class="post-metadata">

**Author:** ![Joseph\_Lord](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joseph_lord/32/22387_2.png) [@Joseph\_Lord](https://forums.swift.org/u/Joseph_Lord)\
**Post date:** [February 13, 2016, 5:18pm UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/8 "2016-02-13T17:18:15Z")

</div>

+1

Didn't even know it was legal. Definitely increases consistency and simplifies the language.

J

> **···**
>
> > On Feb 12, 2016, at 3:00 AM, Erica Sadun via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > [enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4)
> > 
> > Requiring Leading Dot Prefixes for Enum Instance Member Implementations

---

<div class="post-metadata">

**Author:** ![Erica\_Sadun](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/erica_sadun/32/243_2.png) [@Erica\_Sadun](https://forums.swift.org/u/Erica_Sadun)\
**Post date:** [February 12, 2016, 3:26am UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/9 "2016-02-12T03:26:36Z")

</div>

Your modification would affect the language on a large scale rather than creating a small tweak to become less out of sync with existing behavior. Technically, you'd have to introduce name conflict resolution, among other things. And for a community that defeated "required self" only after a large scale heated debate, any change that would make the language less precise and less readable would be a hard sell.

-- E

> **···**
>
> > On Feb 11, 2016, at 8:17 PM, Rob Mayoff via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > On Thu, Feb 11, 2016 at 9:00 PM, Erica Sadun via swift-evolution \<swift-evolution@swift.org \<mailto:swift-evolution@swift.org\>\> wrote:  
> > Unlike static members in structures and classes, enumeration cases can be mentioned in initializers and instance methods without referencing a fully qualified type.
> > 
> > Why not go the other way then and allow instance methods to refer to static members (or class members) directly, without the type name prefix?  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

<div class="post-metadata">

**Author:** ![Chris\_Lattner](https://avatars.discourse-cdn.com/v4/letter/c/bc8723/32.png) [@Chris\_Lattner](https://forums.swift.org/u/Chris_Lattner)\
**Post date:** [February 12, 2016, 4:28am UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/10 "2016-02-12T04:28:00Z")

</div>

As Erica says, this is a worthwhile topic to discuss, but orthogonal from the proposal. Among other things we’d have to have a way to resolve the conflict that comes up when you have both a static and instance method with the same name (this occurs a few places in ObjC APIs).

-Chris

> **···**
>
> > On Feb 11, 2016, at 7:17 PM, Rob Mayoff via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > On Thu, Feb 11, 2016 at 9:00 PM, Erica Sadun via swift-evolution \<swift-evolution@swift.org \<mailto:swift-evolution@swift.org\>\> wrote:  
> > Unlike static members in structures and classes, enumeration cases can be mentioned in initializers and instance methods without referencing a fully qualified type.
> > 
> > Why not go the other way then and allow instance methods to refer to static members (or class members) directly, without the type name prefix?

---

<div class="post-metadata">

**Author:** ![Erica\_Sadun](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/erica_sadun/32/243_2.png) [@Erica\_Sadun](https://forums.swift.org/u/Erica_Sadun)\
**Post date:** [February 12, 2016, 4:24am UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/11 "2016-02-12T04:24:28Z")

</div>

In this write-up I recommend using a prefixed form there too for consistency (staticFunc2), but I'm not married to it.

-- E

> **···**
>
> > On Feb 11, 2016, at 9:09 PM, Brent Royal-Gordon \<brent@architechies.com\> wrote:
> > 
> > > [enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4)
> > > 
> > > Requiring Leading Dot Prefixes for Enum Instance Member Implementations
> > > 
> > > &nbsp;&nbsp;• Proposal: TBD  
> > > &nbsp;&nbsp;• Author(s): Erica Sadun, Chris Lattner  
> > > &nbsp;&nbsp;• Status: TBD  
> > > &nbsp;&nbsp;• Review manager: TBD
> > 
> > +1. I've always found this slightly bizarre.
> > 
> > I assume, though, that if you're writing a static member of an enum, the unprefixed form is fine?
> > 
> > --  
> > Brent Royal-Gordon  
> > Architechies

---

<div class="post-metadata">

**Author:** ![dwaite](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dwaite/32/1200_2.png) [@dwaite](https://forums.swift.org/u/dwaite)\
**Post date:** [February 12, 2016, 6:27am UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/12 "2016-02-12T06:27:56Z")

</div>

Would it be worthwhile to expand this (or create another proposal) to deal with switch cases only allowing dot syntax for use with enum cases?

Luckily OptionSetType is ArrayLiteralConvertable, because "case .True” fails because .True is not an enum case. AFAICT, this is the one case where dot prefixed values and methods are different than switch cases.

-DW

struct Decision : OptionSetType {  
&nbsp;&nbsp;&nbsp;&nbsp;typealias RawValue = UInt8  
&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;let rawValue:RawValue  
&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;internal init(rawValue: UInt8) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.rawValue = rawValue  
&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;static let True = Decision(rawValue: 1)  
&nbsp;&nbsp;&nbsp;&nbsp;static let False = Decision(rawValue: 2)  
}

let godel:Decision = [.True, .False]

switch godel {  
case [.True]:  
&nbsp;&nbsp;&nbsp;&nbsp;print ("true!")  
case [.False]:  
&nbsp;&nbsp;&nbsp;&nbsp;print ("false!")  
case [.True, .False]:  
&nbsp;&nbsp;&nbsp;&nbsp;print ("both true and false!")  
default:  
&nbsp;&nbsp;&nbsp;&nbsp;print ("neither true nor false!")  
}

> **···**
>
> > On Feb 11, 2016, at 9:28 PM, Chris Lattner via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > > On Feb 11, 2016, at 7:17 PM, Rob Mayoff via swift-evolution \<swift-evolution@swift.org \<mailto:swift-evolution@swift.org\>\> wrote:
> > > 
> > > On Thu, Feb 11, 2016 at 9:00 PM, Erica Sadun via swift-evolution \<swift-evolution@swift.org \<mailto:swift-evolution@swift.org\>\> wrote:  
> > > Unlike static members in structures and classes, enumeration cases can be mentioned in initializers and instance methods without referencing a fully qualified type.
> > > 
> > > Why not go the other way then and allow instance methods to refer to static members (or class members) directly, without the type name prefix?
> > 
> > As Erica says, this is a worthwhile topic to discuss, but orthogonal from the proposal. Among other things we’d have to have a way to resolve the conflict that comes up when you have both a static and instance method with the same name (this occurs a few places in ObjC APIs).
> > 
> > -Chris
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

<div class="post-metadata">

**Author:** ![Erica\_Sadun](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/erica_sadun/32/243_2.png) [@Erica\_Sadun](https://forums.swift.org/u/Erica_Sadun)\
**Post date:** [February 12, 2016, 3:57pm UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/13 "2016-02-12T15:57:05Z")

</div>

Are there any reasons why it makes sense to add them to the declaration? There's no other place in the language where a member is declared (vs referenced) using a dot prefix so I'd personally lean towards "no".

-- Erica

> **···**
>
> > On Feb 11, 2016, at 11:41 PM, Carlos Parada \<carlosparada@me.com\> wrote:
> > 
> > Taking consistency further, should the definition also use dot prefixes? For example:
> > 
> > > enum Coin {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;case .Heads, .Tails  
> > > &nbsp;&nbsp;&nbsp;&nbsp;func printMe() {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch self {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Heads: print("Heads")  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Tails: print("Tails")  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> > > &nbsp;&nbsp;&nbsp;&nbsp;}  
> > > }
> > 
> > — Carlos Parada

---

<div class="post-metadata">

**Author:** ![Chris\_Lattner](https://avatars.discourse-cdn.com/v4/letter/c/bc8723/32.png) [@Chris\_Lattner](https://forums.swift.org/u/Chris_Lattner)\
**Post date:** [February 12, 2016, 5:23pm UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/14 "2016-02-12T17:23:55Z")

</div>

Yes, that makes sense to me.

-Chris

> **···**
>
> > On Feb 11, 2016, at 8:09 PM, Brent Royal-Gordon via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > > [enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4)
> > > 
> > > Requiring Leading Dot Prefixes for Enum Instance Member Implementations
> > > 
> > > &nbsp;&nbsp;• Proposal: TBD  
> > > &nbsp;&nbsp;• Author(s): Erica Sadun, Chris Lattner  
> > > &nbsp;&nbsp;• Status: TBD  
> > > &nbsp;&nbsp;• Review manager: TBD
> > 
> > +1. I've always found this slightly bizarre.
> > 
> > I assume, though, that if you're writing a static member of an enum, the unprefixed form is fine?

---

<div class="post-metadata">

**Author:** ![Chris\_Lattner](https://avatars.discourse-cdn.com/v4/letter/c/bc8723/32.png) [@Chris\_Lattner](https://forums.swift.org/u/Chris_Lattner)\
**Post date:** [February 12, 2016, 5:26pm UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/15 "2016-02-12T17:26:10Z")

</div>

> Taking consistency further, should the definition also use dot prefixes?

I agree with others’ comments downthread. The goal here is to make enum cases more similar to static members, since that is how they behave. Both static members and enum cases can be referred to with the leading dot syntax already, and we wouldn’t add dot to the declaration of static members.

-Chris

> **···**
>
> > On Feb 11, 2016, at 10:41 PM, Carlos Parada via swift-evolution \<swift-evolution@swift.org\> wrote:
> 
> > For example:
> > 
> > > enum Coin {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;case .Heads, .Tails  
> > > &nbsp;&nbsp;&nbsp;&nbsp;func printMe() {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch self {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Heads: print("Heads")  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Tails: print("Tails")  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> > > &nbsp;&nbsp;&nbsp;&nbsp;}  
> > > }
> > 
> > — Carlos Parada  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

<div class="post-metadata">

**Author:** ![dwaite](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dwaite/32/1200_2.png) [@dwaite](https://forums.swift.org/u/dwaite)\
**Post date:** [February 12, 2016, 4:45pm UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/16 "2016-02-12T16:45:08Z")

</div>

I like this, but I think it needs to handle more cases to truly promote consistency.

In static contexts, use of the case is consistent with that of a static variable or function (value directly in scope, so no dot prefix shortcut necessary).

enum Booly {  
&nbsp;&nbsp;&nbsp;&nbsp;case truth  
&nbsp;&nbsp;&nbsp;&nbsp;case falsehood  
&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;static let yes = truth  
&nbsp;&nbsp;&nbsp;&nbsp;static let no = falsehood

&nbsp;&nbsp;&nbsp;&nbsp;static func defaulted() -\> Booly {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return truth  
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;static func workingAlternative() -\> Booly {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return yes  
&nbsp;&nbsp;&nbsp;&nbsp;}

It is however a special case in the non-static context:

extension Booly {  
&nbsp;&nbsp;&nbsp;&nbsp;func isDefault() -\> Bool {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return self == truth  
&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;func brokenYesVersion() -\> Bool {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// return self == yes // Error: Static member 'yes' cannot be used on instance of type 'Booly'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return self == .yes  
&nbsp;&nbsp;&nbsp;&nbsp;}  
}

And case usage is inconsistent in the body of a switch statement. In situations like an OptionSetType implementation, the compiler will complain about use of dot syntax w.r.t. not being an enumeration member.

import Foundation

let flags:CFStringCompareFlags = [.CompareAnchored]

switch flags {  
// case .CompareAnchored: // Error: Enum case 'CompareAnchored' ont found in type 'CFStringCompareFlags'  
case CFStringCompareFlags.CompareAnchored:  
&nbsp;&nbsp;&nbsp;&nbsp;print("Anchored")  
default:  
&nbsp;&nbsp;&nbsp;&nbsp;()  
}

In the case of enumerations, it will complain about anything from the enumerated type other than the case label!

let b:Booly = .yes

// switch b {  
// case yes: // Error: Use of unresolved identifier ‘yes’  
// case .yes: // Error: Enum case 'yes' not found in type 'Booly'  
// case Booly.yes: // Error: Enum case 'yes' not found in type 'Booly'  
//}

let externalYes = Booly.truth

switch b {  
case externalYes:  
&nbsp;&nbsp;&nbsp;&nbsp;print ("finally, yes!")  
default:  
&nbsp;&nbsp;&nbsp;&nbsp;()  
}

IMHO, the \*only\* thing that the compiler should do special with case variable usage is that, when the type beings switched over is an enum and the cases of that enum are all specified as possible cases of the switch, not require the use of a default section.

(playground code copied to [case-inconsistencies.swift · GitHub](https://gist.github.com/dwaite/60c8dc05e498b747d0f2) )

-DW

> **···**
>
> > On Feb 12, 2016, at 7:23 AM, Daniel Steinberg via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > +1 for consistency reasons
> > 
> > > On Feb 11, 2016, at 10:00 PM, Erica Sadun via swift-evolution \<swift-evolution@swift.org \<mailto:swift-evolution@swift.org\>\> wrote:
> > > 
> > > [enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4)
> > > 
> > > Requiring Leading Dot Prefixes for Enum Instance Member Implementations
> > > 
> > > Proposal: TBD  
> > > Author(s): Erica Sadun \<[http://github.com/erica&gt;](http://github.com/erica&gt;), Chris Lattner \<[https://github.com/lattner&gt](https://github.com/lattner&gt);  
> > > Status: TBD  
> > > Review manager: TBD  
> > > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#introduction&gt;Introduction)
> > > 
> > > Enumeration cases are essentially static not instance type members. Unlike static members in structures and classes, enumeration cases can be mentioned in initializers and instance methods without referencing a fully qualified type. This makes little sense. In no other case can an instance implementation directly access a static member. This proposal introduces a rule that requires leading dots or fully qualified references (EnumType.caseMember) to provide a more consistent developer experience to clearly disambiguate static cases from instance members.
> > > 
> > > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#motivation&gt;Motivation)
> > > 
> > > Swift infers the enclosing type for a case on a developer's behalf when the use is unambiguously of a single enumeration type. Inference enables you to craft switch statements like this:
> > > 
> > > switch Coin() {  
> > > case .Heads: print("Heads")  
> > > case .Tails: print("Tails")  
> > > }  
> > > A leading dot has become a conventional shorthand for "enumeration case" across the language. When used internally in enum implementations, a leading dot is not required, nor is a type name to access the static case member. The following code is legal in Swift.
> > > 
> > > enum Coin {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;case Heads, Tails  
> > > &nbsp;&nbsp;&nbsp;&nbsp;func printMe() {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch self {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case Heads: print("Heads") // no leading dot  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Tails: print("Tails") // leading dot  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> > > 
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if self == Heads { // no leading dot  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("This is a head")  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> > > 
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if self == .Tails { // leading dot  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("This is a tail")  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> > > &nbsp;&nbsp;&nbsp;&nbsp;}
> > > 
> > > &nbsp;&nbsp;&nbsp;&nbsp;init() {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let cointoss = arc4random\_uniform(2) == 0  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self = cointoss ? .Heads : Tails // mix and match leading dots  
> > > &nbsp;&nbsp;&nbsp;&nbsp;}  
> > > }  
> > > This quirk produces a language inconsistency that can confuse developers and contravenes the guiding Principle of Least Astonishment. We propose to mandate a leading dot. This will bring case mentions into lock-step with the conventions used to reference them outside of enumeration type implementations.
> > > 
> > > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#detail-design&gt;Detail) Design
> > > 
> > > Under this rule, the compiler will require a leading dot for all case members. The change will not affect other static members, which require fully qualified references from instance methods and infer self from static methods.
> > > 
> > > enum Coin {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;case Heads, Tails  
> > > &nbsp;&nbsp;&nbsp;&nbsp;static func doSomething() { print("Something") }  
> > > &nbsp;&nbsp;&nbsp;&nbsp;static func staticFunc() { doSomething() } // does not require leading dot  
> > > &nbsp;&nbsp;&nbsp;&nbsp;static func staticFunc2() { let foo = .Tails } // requires leading dot  
> > > &nbsp;&nbsp;&nbsp;&nbsp;func instanceFunc() { self.dynamicType.doSomething() } // requires full qualification  
> > > &nbsp;&nbsp;&nbsp;&nbsp;func otherFunc() { if self == .Heads ... } // requires leading dot, also initializers
> > > 
> > > &nbsp;&nbsp;&nbsp;&nbsp;/// ...  
> > > }  
> > > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#alternatives-considered&gt;Alternatives) Considered
> > > 
> > > Other than leaving the status quo, the language could force instance members to refer to cases using a fully qualified type, as with other static members.  
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > swift-evolution mailing list  
> > > swift-evolution@swift.org \<mailto:swift-evolution@swift.org\>  
> > > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

<div class="post-metadata">

**Author:** ![griotspeak](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/griotspeak/32/1966_2.png) [@griotspeak](https://forums.swift.org/u/griotspeak)\
**Post date:** [February 12, 2016, 3:46pm UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/17 "2016-02-12T15:46:12Z")

</div>

+1 and I would not object to requiring the leading dot for enum  
declarations.

> **···**
>
> On Fri, Feb 12, 2016 at 9:23 AM, Daniel Steinberg via swift-evolution \< swift-evolution@swift.org\> wrote:
> 
> > +1 for consistency reasons
> > 
> > On Feb 11, 2016, at 10:00 PM, Erica Sadun via swift-evolution \< \> swift-evolution@swift.org\> wrote:
> > 
> > [enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4)
> > 
> > Requiring Leading Dot Prefixes for Enum Instance Member Implementations
> > 
> > &nbsp;&nbsp;&nbsp;- Proposal: TBD  
> > &nbsp;&nbsp;&nbsp;- Author(s): Erica Sadun \<[http://github.com/erica&gt;](http://github.com/erica&gt;), Chris Lattner  
> > &nbsp;&nbsp;&nbsp;\<[https://github.com/lattner&gt](https://github.com/lattner&gt);  
> > &nbsp;&nbsp;&nbsp;- Status: TBD  
> > &nbsp;&nbsp;&nbsp;- Review manager: TBD
> > 
> > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#introduction&gt);  
> > Introduction
> > 
> > Enumeration cases are essentially static not instance type members. Unlike  
> > static members in structures and classes, enumeration cases can be  
> > mentioned in initializers and instance methods without referencing a fully  
> > qualified type. This makes little sense. In no other case can an instance  
> > implementation directly access a static member. This proposal introduces a  
> > rule that requires leading dots or fully qualified references  
> > (EnumType.caseMember) to provide a more consistent developer experience to  
> > clearly disambiguate static cases from instance members.  
> > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#motivation&gt;Motivation)
> > 
> > Swift infers the enclosing type for a case on a developer's behalf when  
> > the use is unambiguously of a single enumeration type. Inference enables  
> > you to craft switch statements like this:
> > 
> > switch Coin() {case .Heads: print("Heads")case .Tails: print("Tails")  
> > }
> > 
> > A leading dot has become a conventional shorthand for "enumeration case"  
> > across the language. When used internally in enum implementations, a  
> > leading dot is not required, nor is a type name to access the static case  
> > member. The following code is legal in Swift.
> > 
> > enum Coin {  
> > &nbsp;&nbsp;&nbsp;&nbsp;case Heads, Tails  
> > &nbsp;&nbsp;&nbsp;&nbsp;func printMe() {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch self {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case Heads: print("Heads") // no leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Tails: print("Tails") // leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if self == Heads { // no leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("This is a head")  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if self == .Tails { // leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("This is a tail")  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> > &nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;init() {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let cointoss = arc4random\_uniform(2) == 0  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self = cointoss ? .Heads : Tails // mix and match leading dots  
> > &nbsp;&nbsp;&nbsp;&nbsp;}  
> > }
> > 
> > This quirk produces a language inconsistency that can confuse developers  
> > and contravenes the guiding \*Principle of Least Astonishment\*. We propose  
> > to mandate a leading dot. This will bring case mentions into lock-step with  
> > the conventions used to reference them outside of enumeration type  
> > implementations.  
> > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#detail-design&gt;Detail)  
> > Design
> > 
> > Under this rule, the compiler will require a leading dot for all case  
> > members. The change will not affect other static members, which require  
> > fully qualified references from instance methods and infer self from  
> > static methods.
> > 
> > enum Coin {  
> > &nbsp;&nbsp;&nbsp;&nbsp;case Heads, Tails  
> > &nbsp;&nbsp;&nbsp;&nbsp;static func doSomething() { print("Something") }  
> > &nbsp;&nbsp;&nbsp;&nbsp;static func staticFunc() { doSomething() } // does not require leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;static func staticFunc2() { let foo = .Tails } // requires leading dot  
> > &nbsp;&nbsp;&nbsp;&nbsp;func instanceFunc() { self.dynamicType.doSomething() } // requires full qualification  
> > &nbsp;&nbsp;&nbsp;&nbsp;func otherFunc() { if self == .Heads ... } // requires leading dot, also initializers
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;/// ...  
> > }
> > 
> > \<[enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4#alternatives-considered&gt;Alternatives)  
> > Considered  
> > Other than leaving the status quo, the language could force instance  
> > members to refer to cases using a fully qualified type, as with other  
> > static members.  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

<div class="post-metadata">

**Author:** ![cryo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cryo/32/13218_2.png) [@cryo](https://forums.swift.org/u/cryo)\
**Post date:** [February 12, 2016, 6:24pm UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/18 "2016-02-12T18:24:56Z")

</div>

I think wording it like that misleadingly suggests that the proposal was in any way near passing, which certainly didn’t seem to be the case.

-Sune

> **···**
>
> > On 12 Feb 2016, at 04:26, Erica Sadun via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > And for a community that defeated "required self" only after a large scale heated debate,

---

<div class="post-metadata">

**Author:** ![possen](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@possen](https://forums.swift.org/u/possen)\
**Post date:** [February 13, 2016, 5:40pm UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/19 "2016-02-13T17:40:15Z")

</div>

I am assuming there would be no dot in front of \_?

switch value {  
&nbsp;&nbsp;case .A: “A”  
&nbsp;&nbsp;case .B: “B”  
&nbsp;&nbsp;case .\_:”D” // this is not correct?  
}

> **···**
>
> > On Feb 13, 2016, at 9:18 AM, Joseph Lord via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > +1
> > 
> > Didn't even know it was legal. Definitely increases consistency and simplifies the language.
> > 
> > J
> > 
> > On Feb 12, 2016, at 3:00 AM, Erica Sadun via swift-evolution \<swift-evolution@swift.org \<mailto:swift-evolution@swift.org\>\> wrote:
> > 
> > > [enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4)
> > > 
> > > Requiring Leading Dot Prefixes for Enum Instance Member Implementations
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

<div class="post-metadata">

**Author:** ![Erica\_Sadun](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/erica_sadun/32/243_2.png) [@Erica\_Sadun](https://forums.swift.org/u/Erica_Sadun)\
**Post date:** [February 13, 2016, 7:31pm UTC](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404/20 "2016-02-13T19:31:36Z")

</div>

No. The wildcard match does not require a dot prefix.

-- E

> **···**
>
> > On Feb 13, 2016, at 10:40 AM, Paul Ossenbruggen via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > I am assuming there would be no dot in front of \_?
> > 
> > switch value {  
> > &nbsp;&nbsp;case .A: “A”  
> > &nbsp;&nbsp;case .B: “B”  
> > &nbsp;&nbsp;case .\_:”D” // this is not correct?  
> > }
> > 
> > > On Feb 13, 2016, at 9:18 AM, Joseph Lord via swift-evolution \<swift-evolution@swift.org \<mailto:swift-evolution@swift.org\>\> wrote:
> > > 
> > > +1
> > > 
> > > Didn't even know it was legal. Definitely increases consistency and simplifies the language.
> > > 
> > > J
> > > 
> > > On Feb 12, 2016, at 3:00 AM, Erica Sadun via swift-evolution \<swift-evolution@swift.org \<mailto:swift-evolution@swift.org\>\> wrote:
> > > 
> > > > [enums.md · GitHub](https://gist.github.com/erica/e0b8a3a22ab716a19db4)
> > > > 
> > > > Requiring Leading Dot Prefixes for Enum Instance Member Implementations
> > > 
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > swift-evolution mailing list  
> > > swift-evolution@swift.org \<mailto:swift-evolution@swift.org\>  
> > > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

[Next page](https://forums.swift.org/t/discussion-enum-leading-dot-prefixes/1404.md?page=2)
