[swift-evolution] Swift case conventions for Enums

Sean Heber sean at fifthace.com
Tue Dec 22 15:02:29 CST 2015


I’ve run into a few situations where the reverse is true, for example:

enum Priority {
    case Low, Default, High
}

I would not be able to use the word “default” if it was lowercase since it would conflict with the keyword. In fact, in this one project, I have at least 2 enums that would have cases that conflict with language keywords if the convention were lowercase. Just throwing this out there. :)

l8r
Sean


> On Dec 22, 2015, at 10:41 AM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Dec 21, 2015, at 3:58 PM, Michael Wells via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> I love that Swift has a published API design guidelines at https://swift.org/documentation/api-design-guidelines.html, but one thing about it bugs me: the use of UpperCamelCase for cases. I know this ship has long sailed, but why didn't the team choose lowerCamelCase for these? The current style seems inconsistent and requires an “instances are lowerCamelCase, aside from Enums” clarification.
> 
> Another reason to change the convention is that it's common to want to name cases the same as their payload type. When both use the UpperCamelCase convention, you have to disambiguate the name collision:
> 
> enum JSON {
>   case String(Swift.String)
>   case Array(Swift.Array<JSON>)
>   /* etc. */
> }
> 
> Using lowerCamelCase would avoid the collision.
> 
> -Joe
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list