Skip to content

Enum "shorter dot" syntax sugar #1183

Closed
@dagba

Description

@dagba

Hello there! 🖖

I've found the explicitly specifying an enum's name is too boilerplate. So can u please add "shorter dot" syntax sugar?

Example:

enum CompassPoint {
    case north
    case south
    case east
    case west
}

var directionToHead = CompassPoint.west The type of directionToHead is inferred when it’s initialized with one of the possible values of CompassPoint. Once directionToHead is declared as a CompassPoint, you can set it to a different CompassPoint value using a shorter dot syntax:

directionToHead = .east The type of directionToHead is already known, and so you can drop the type when setting its value. This makes for highly readable code when working with explicitly typed enumeration values.

if directionToHead == .east { doSomething() }

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProposed language feature that solves one or more problemsstate-duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions