I don't have a complete answer, but maybe what I found will help someone figure out the rest of it:
a - b can be interpreted as one of the following:
func -(lhs: UInt, rhs: UInt) -> UInt func -<T : Strideable>(lhs: T, rhs: T) -> T.Stride
Thus, the result will be either UInt or UInt.Stride . Literal 1 can be interpreted somehow because it works:
let f: UInt.Stride = 1
For some unknown reason += does Swift interpret a - b as UInt.Stride instead of UInt . Note that the following value gives the same error:
let e: UInt.Stride = a - b
If you use UInt(1) instead of 1 , it works:
string += a - b > UInt(1) ? "true" : "false"
I believe this works because it makes Swift see a - b as a result of UInt , because it only has > that accepts two UInt (not UInt.Stride and UInt ). Note if you press 1 as UInt.Stride :
let f: UInt.Stride = 1
this gives the same error:
string += a - b > f ? "true" : "false"
Another workaround is to use UInt() around a - b :
string += UInt(a - b) > 1 ? "true" : "false"
source share