[swift-evolution] [Discussion] Enum Leading Dot Prefixes

David Waite david at alkaline-solutions.com
Fri Feb 12 00:27:56 CST 2016

Would it be worthwhile to expand this (or create another proposal) to deal with switch cases only allowing dot syntax for use with enum cases?

Luckily OptionSetType is ArrayLiteralConvertable, because "case .True” fails because .True is not an enum case. AFAICT, this is the one case where dot prefixed values and methods are different than switch cases.


struct Decision : OptionSetType {
    typealias RawValue = UInt8
    let rawValue:RawValue
    internal init(rawValue: UInt8) {
        self.rawValue = rawValue
    static let True = Decision(rawValue: 1)
    static let False = Decision(rawValue: 2)

let godel:Decision = [.True, .False]

switch godel {
case [.True]:
    print ("true!")
case [.False]:
    print ("false!")
case [.True, .False]:
    print ("both true and false!")
    print ("neither true nor false!")

> On Feb 11, 2016, at 9:28 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
>> On Feb 11, 2016, at 7:17 PM, Rob Mayoff via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> On Thu, Feb 11, 2016 at 9:00 PM, Erica Sadun via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> Unlike static members in structures and classes, enumeration cases can be mentioned in initializers and instance methods without referencing a fully qualified type.
>> Why not go the other way then and allow instance methods to refer to static members (or class members) directly, without the type name prefix?
> As Erica says, this is a worthwhile topic to discuss, but orthogonal from the proposal.  Among other things we’d have to have a way to resolve the conflict that comes up when you have both a static and instance method with the same name (this occurs a few places in ObjC APIs).
> -Chris
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160211/672ab86c/attachment-0001.html>

More information about the swift-evolution mailing list