编译器错误 – 限制表达式中的术语数量?

前端之家收集整理的这篇文章主要介绍了编译器错误 – 限制表达式中的术语数量?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
编辑:这是由apple作为编译器错误确认的。

第一个如果下面的表达式(17项)编译,并产生预期结果(false)。
第二个if表达式(18项)失败并显示错误消息:

Cannot invoke ‘||’ with an argument list of type ‘($T106,$T110)’.

这两个表达式是相同的,除了额外的术语。

我在解决问题时没有任何问题,但是我不明白是什么抱怨。有人可以启发我,我所做的愚蠢的错误是什么?温柔,非常没有经验的编码器在这里。

import Darwin

var a = -1
if
    a == 0 ||
        a == 1 ||
        a == 2 ||
        a == 3 ||
        a == 4 ||
        a == 5 ||
        a == 6 ||
        a == 7 ||
        a == 8 ||
        a == 9 ||
        a == 10 ||
        a == 11 ||
        a == 12 ||
        a == 13 ||
        a == 14 ||
        a == 15 ||
        a == 16 ||
        a == 17 { println("value was true") } else { println("value was false")}

if
    a == 0 ||
        a == 1 ||
        a == 2 ||
        a == 3 ||
        a == 4 ||
        a == 5 ||
        a == 6 ||
        a == 7 ||
        a == 8 ||
        a == 9 ||
        a == 10 ||
        a == 11 ||
        a == 12 ||
        a == 13 ||
        a == 14 ||
        a == 15 ||
        a == 16 ||
        a == 17 ||
        a == 18 { println("value was true") } else { println("value was false")}
虽然该问题已经解决了,但您可以使用这个:
switch a {
case 0...17:
    println("value was true")
default:
    println("value was false")
}
原文链接:https://www.f2er.com/swift/320327.html

猜你在找的Swift相关文章