[swift-evolution] Dot notation as shorthand in subscripts and functions
swift-evolution at haravikk.com
Sat Jan 16 05:19:05 CST 2016
Hmm, that’s a shame, as other than switch cases I don’t use the leading-dot notation for anything else; personally I’d find it much more useful as a shorthand for cutting boilerplate around instances, as they can more easily become nested deeply than statics.
That said, I disagree that this behaviour would mean that it will “always” conflict; as with an enum argument it will still only conflict if the type has both a local and static item with exactly the same name.
In your example, textColor’s type would need to have both a static and local .whiteColor() that could result in ambiguity, which seems unlikely. If there’s only a static whiteColor then there’s no ambiguity.
> On 16 Jan 2016, at 10:24, Brent Royal-Gordon <brent at architechies.com> wrote:
>> When used in a switch statement the dot notation is a kind of shorthand reference to the type of an enum, but it also seems like for non enums it could be a shorthand reference to self, allowing us to avoid having to write out variable references in a few common cases.
> I think you don't realize how broad the existing leading-dot feature is.
> Leading dot can be used in any place where a type can be inferred to access a static member of that type. For instance, it also allows this:
> textField.textColor = .whiteColor()
> Because it's not limited to just enums, the existing meaning would almost *always* conflict with the meaning you propose.
> Brent Royal-Gordon
More information about the swift-evolution