Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift has implicit enums #7

Open
kasperpeulen opened this issue Aug 9, 2018 · 1 comment
Open

Swift has implicit enums #7

kasperpeulen opened this issue Aug 9, 2018 · 1 comment

Comments

@kasperpeulen
Copy link

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 kasperpeulen changed the title Swift have implicit enums Swift has implicit enums Aug 9, 2018
@munificent
Copy link
Owner

Thanks for the pointer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants