Xcode 9 beta 3 - Swift 3.2: comparing optional

282 Views Asked by At

Project which compiles fine in Xcode 8.3.2 shows many compilation errors around comparing optional/non optional value with ==

What I have found is an older proposal for removing coparison <> for the same: https://github.com/apple/swift-evolution/blob/master/proposals/0121-remove-optional-comparison-operators.md

So now in Xcode 9, I can not even compare two optionals:

    let xxx: String? =  "A"
    let yyy: String? = "B"

    if xxx == yyy { //ERROR: Ambiguous use of operator '=='

    }

Could someone point me to a resource where this would be explained? Or is it just a temporary bug?

Thanks

1

There are 1 best solutions below

1
On BEST ANSWER

Using XCode 9 beta (9M136h) and Swift 4, your instruction compiles.

Variants of == and != which accept optional operands are still useful, and their results unsurprising, so they will remain.

Remove the versions of <, <=, >, and >= which accept optional operands.

So your instruction should works either in Swift 3.2 or Swift 4. Check the swift version you are using in the build settings -> Swift Language Version.