Search code examples
swiftswift3swift4code-readability

Enclose right hand side of expression in Swift language


Is there a way to enclose right hand side of an assignment expression in Swift using some brackets. I had the habit of using small brackets to enclose RHS of assignment expression in Objective C to make it more readable if the RHS is a big expression.

Adding a simple example Example:

func function1() -> Bool {
    return // Returns a bool
}

func function2() -> Bool {
    return // Returns a bool
}

func findResult() {
    let result1 = function1() || function2()
    let result2 = (function1() || function2())
}

Now XCode shows inferred type of result1 as Bool and result2 as (Bool). Refer to attached images. enter image description here
enter image description here

Is there a way to enclose complete RHS of the assignment expression inside brackets? It is not needed for above mentioned simple case but useful if RHS internally has many operators in it(Code readability).


Solution

  • @MartinR mentioned has mentioned link to another question where it is confirmed Bool and (Bool) are same. Thanks martin for help.