逗号分隔条件和使用双符号的条件之间有什么区别

Car*_*rds 8 conditional swift

我最近遇到过这种情况,使用if/let并了解它的功能归功于这篇文章.据我了解,在执行进程块之前需要满足这两个条件.我现在已经到了我在常规条件语句中看到它的地步:

if existingTextHasDecimalSeparator != nil, replacementTextHasDecimalSeparator != nil {
    return false
} else {
    return true
}
Run Code Online (Sandbox Code Playgroud)

完成上述操作与简单使用之间有什么区别&&

if existingTextHasDecimalSeparator != nil && replacementTextHasDecimalSeparator != nil {
    return false
} else {
    return true
}
Run Code Online (Sandbox Code Playgroud)

Key*_*ose 9

当可选绑定布尔条件时使用逗号,例如if let a = a, a.isValid()而是&&典型的AND运算符

  • 是的,但在这种情况下没有可选绑定。 (10认同)

The*_*Baj 5

&&用于将条件分组和使用逗号似乎没有区别。到目前为止,我也只看到它与可选绑定一起使用,但是显然,它也适用于常规条件,因为以下代码片段可以正常工作。

let bool1 = true;
let bool2 = true;

if bool1 , bool2 {
    print("true");
} else {
    print("false")
}
Run Code Online (Sandbox Code Playgroud)