[swift-evolution] Carriage Return in Collection Array Literal Initializer
Ivan Oparin
oparin at me.com
Sat Apr 23 17:27:26 CDT 2016
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
More information about the swift-evolution
mailing list