[swift-evolution] Dot notation as shorthand in subscripts and functions

Vatsal Manot vatsal.manot at yahoo.com
Sat Jan 16 03:48:14 CST 2016


-1 from me. The problems you’ve mentioned can either easily be overcome via extensions, or aren’t big enough to justify the new syntax.

I have personally encountered one of the problems you are describing, and the following is how I resolved it: 

extension MutableCollectionType
{
    public var first: Generator.Element?
    {
        get
        {
            return first
        }
        
        set
        {
            if !isEmpty, let newValue = newValue
            {
                self[startIndex] = newValue
            }
        }
    }
}

var array: [Int] = [0, 2, 3, 4, 5]

array.first
array.first = 1


More information about the swift-evolution mailing list