willowtreeapps / swift-style-guide

The official Swift style guide for WillowTree, Inc.
MIT License
16 stars 3 forks source link

Array property initialization #18

Closed aenewton closed 8 years ago

aenewton commented 8 years ago

@ianterrell and I were having a discussion about array property initialization, and I wanted to move that here. Currently, the style guide suggests using:

var names = [String]().

Ian is suggesting we move to: var names: [String] = []

Thoughts? I'm personally in favor of how we currently have it.

Grigs-b commented 8 years ago

I use the second one typically. Not really a fan of []()

mrketchup commented 8 years ago

I am a fan of using literals when possible. This goes for dictionaries as well

var foo: [String: Bar] = [:]
kconner commented 8 years ago

Second, seconded. Syntactic sugar types don't look right to me with parentheses hanging off the end. Agreed re: dictionaries.

You wouldn't say var foo = String?.None, you'd say var foo: String? = nil

aenewton commented 8 years ago

You all have managed to convince me. I'm now on board with the change.

mattyohe commented 8 years ago

Someone needs to go through ray's to look for updates/swift 3 updates before we add too many new issues, as this is also the preferred way mentioned there:

https://github.com/raywenderlich/swift-style-guide#type-annotation-for-empty-arrays-and-dictionaries

eriklamanna commented 8 years ago

I believe this is now updated in the latest push to master.