A comma is already allowed after the last element in an array or dictionary
literal:
Welcome to Apple Swift version 2.2 (swiftlang-703.0.18.1 clang-703.0.29). Type
:help for assistance.
1> let x = [1, 2, 3,]
x: [Int] = 3 values {
[0] = 1
[1] = 2
[2] = 3
}
2> let y = [1: "one", 2: "two", 3: "three",]
y: [Int : String] = 3 key/value pairs {
[0] = {
key = 2
value = "two"
}
[1] = {
key = 3
value = "three"
}
[2] = {
key = 1
value = "one"
}
}
> On Apr 25, 2016, at 9:25 AM, Kenny Leung via swift-evolution
> <[email protected]> wrote:
>
> This is brilliant! If semicolons are optional, why not commas?
>
> -Kenny
>
>
>> On Apr 24, 2016, at 2:40 PM, Ross O'Brien via swift-evolution
>> <[email protected]> wrote:
>>
>> There was a discussion some time ago about making the comma of the last
>> entry optional, because adding entries meant changing more than one line of
>> code and this annoyed users of version control systems. This is an elegant
>> approach to that problem.
>> I don't know if it's a practical approach for the compiler, but if it is
>> then I'm in favour.
>>
>> On Sat, Apr 23, 2016 at 11:27 PM, Ivan Oparin via swift-evolution
>> <[email protected]> wrote:
>> Sometimes in is necessary to initialize a collection with a long list of
>> items. Consider this example:
>>
>> let dictionaryWithALotOfItems = ["someString0" : SomeFunctionality.0,
>> "someString1" : SomeFunctionality.0, "someString2" : SomeFunctionality.0,
>> "someString3" : SomeFunctionality.1, "someString4" : SomeFunctionality.1]
>>
>> items are separated with a comma, and we can ommit it for the last item.
>>
>> However, sometimes we deal with longer collections and we can make the code
>> more readable by writing each item on it's own line:
>>
>> let dictionaryWithALotOfItems = [
>> "someString0" : SomeFunctionality.0,
>> "someString1" : SomeFunctionality.0,
>> "someString2" : SomeFunctionality.0,
>> "someString3" : SomeFunctionality.1,
>> "someString4" : SomeFunctionality.1
>> ]
>>
>> now it looks much better except the comma in the end of line does not look
>> natural
>>
>> that is espessialy true for the line with a closure:
>> "someString5" : SomeFunctionality.2 { some functionality },
>>
>> some closures are longer:
>> "someString6" : SomeFunctionality.3 {
>> some
>> long
>> closure
>> functionality
>> },
>>
>> if Swift could treat carriage return in array literal initializer as a
>> separation for the items, that would make some collections look cleaner:
>>
>> let dictionaryWithALotOfItems = [
>> "someString0" : SomeFunctionality.0
>> "someString1" : SomeFunctionality.0
>> "someString2" : SomeFunctionality.0
>> "someString3" : SomeFunctionality.1
>> "someString4" : SomeFunctionality.1
>> ]
>>
>> just like a line without a semicolon looks better
>> _______________________________________________
>> swift-evolution mailing list
>> [email protected]
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>> _______________________________________________
>> swift-evolution mailing list
>> [email protected]
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution