I have a question regarding the one liner if statements, as I have not found it mentioned in the guide. Is it okay to be using something like:
var playerMark = player == 1 ? "x" : "o"
Thanks!
Personally I am a fan. I am a little less of a fan of nested ternary one liners. BTW, I think that should be a let
:)
I prefere to put all ternary operators inside (...). It looks much more readable for me:
let playerMark = ( player == 1 ? "x" : "o" ) // lets var be let
Are there not cases when using this would be bad.
I came across this code in a repo I contribute to and I find this:
hostNameLabel.text = host.name == nil || (host.name!.isEmpty) ? "DetailsDetails.NoName".localized : host.name
a lot less readable than this
if host.name == nil || host.name!.isEmpty {
"DetailsDetails.NoName".localized
} else {
host.name
}
Most helpful comment
I prefere to put all ternary operators inside (...). It looks much more readable for me: