In a recent question, the poster had this interesting line of code:
self.view.backgroundColor = .whiteColor()
I was surprised to see this.
I could not find anything along the lines in the documentation. However, the way it works, I believe, is that Swift knows which type is being in context from self.view.backgroundColor
, therefore expression starting directly with a dot should be a static on that type (either a static method or static property).
The following works nicely:
struct Foo {
static func fooMethod() -> Foo {
return Foo()
}
static var fooProperty: Foo = Foo()
}
var foo: Foo
foo = .fooMethod()
foo = .fooProperty