In a recent question, the poster had this interesting line of code:
self.view.backgroundColor = .whiteColor()
I was surprised to see this.
Looks like the rule is: if a type has a static method that returns that type, you can skip the type’s name if the return type is already determined:
struct S {
static func staticmethod() -> S {
return S()
}
static var staticproperty: S {
return S()
}
}
let s1: S = .staticmethod()
let s2: S = .staticproperty
I wonder if this is intentional, or a side-effect of the implementation of Enums which, given this feature, could maybe be thought of as syntactic sugar for something like this:
struct FakeEnum {
let raw: Int
static var FirstCase: FakeEnum { return FakeEnum(raw: 0) }
static var SecondCase: FakeEnum { return FakeEnum(raw: 1) }
}
let e: FakeEnum = .FirstCase