这是indexloc提供的服务,不要输入任何密码
Skip to content

Revisit ternary operator section #370

@technocidal

Description

@technocidal

Swift 5.9 introduced the final implementation of of SE-0380.

It is now possible to rewrite a given ternary operator using if/swift expressions

let value = 5
result = value != 0 ? x : y

turns into

let value = 5
result = if value != 0 {
  x
} else {
  y
}

In my opinion this syntax can lead to a more readable result than using a ternary operator making it more useful for evaluating complex conditions and expands the complexity of conditions that are evaluated during assignment. It might be a good idea to mention it or include additional language describing best practices.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions