ui-as-code icon indicating copy to clipboard operation
ui-as-code copied to clipboard

Swift has implicit enums

Open kasperpeulen opened this issue 7 years ago • 1 comments

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);

kasperpeulen avatar Aug 09 '18 10:08 kasperpeulen

Thanks for the pointer!

munificent avatar Oct 04 '18 16:10 munificent