Skip to content

Swift has implicit enums #7

@kasperpeulen

Description

@kasperpeulen

About: https://github.com/munificent/ui-as-code/blob/master/ideas/implicit-enums.md

Swift has this feature already, it is quite popular I belief, so you may draw some inspiration from it.

It works for static members of classes, that return the same type as well as for enums.

class Fruit {
    static var apple = Fruit(name: "apple");
    static var banana = Fruit(name: "banana");
    
    var name: String;
    
    init(name: String) {
        self.name = name;
    }
}

func printFruit(fruit: Fruit) {
    print(fruit.name);
}

// .banana is here inferred as Fruit.banana
printFruit(fruit: .banana);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions