简体   繁体   English

如何将 Int 类型的值转换为预期的参数类型 Bool

[英]How to convert value of type Int to expected argument type Bool

I'm trying to check if 1Array.count is greater than the counts of three other arrays, 2Array , 3Array , and 4Array :我正在尝试检查1Array.count是否大于其他三个 arrays、 2Array3Array4Array的计数:

if 1Array.count > 2Array.count && 3Array.count && 4Array.count {
    // code
}

but I have this error:但我有这个错误:

Cannot convert value of type 'Int' to expected argument type 'Bool'

How can I fix it?我该如何解决?

If you are trying to check that all arrays are < 1Array then your If stmt needs to read like this:如果您尝试检查所有 arrays 是否 < 1Array 那么您的If stmt 需要如下所示:

if 1Array.count > 2Array.count && 1Array.count > 3Array.count && 1Array.count > 4Array.count {
}

Better yet:更好的是:

if array1.count > array2.count, array1.count > array3.count, array1.count > array4.count {
    }

Rename the variables might be good too as I show in the above example.正如我在上面的示例中所示,重命名变量也可能很好。

If your intent is to make sure that 1Array count is greater than all the other collections count you can simply compare it against the maximum value of them:如果您的意图是确保 1Array 计数大于所有其他 collections 计数,您可以简单地将其与它们的最大值进行比较:

if array1.count > max(array2.count, array3.count, array4.count) {
    // your code
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将Int类型的值转换为预期的参数类型Bool - Cannot convert value of type Int to expected argument type Bool 无法将类型&#39;(_)-&gt;()&#39;的值转换为预期的参数类型&#39;((Bool,Error?)-&gt; Void)? - Cannot convert value of type '(_) -> ()' to expected argument type '((Bool, Error?) -> Void)?' 无法将“KotlinBoolean”类型的值转换为预期的参数类型“Bool” - Cannot convert value of type 'KotlinBoolean' to expected argument type 'Bool' 无法将类型&#39;(_) - &gt; Bool&#39;的值转换为预期的参数类型&#39;NSPredicate&#39; - Cannot convert value of type '(_) -> Bool' to expected argument type 'NSPredicate' 无法将“字符串”类型的值转换为预期的参数类型“布尔” - Cannot convert value of type 'String' to expected argument type 'Bool' Swift:无法将类型&#39;() - &gt; Bool&#39;的值转换为预期的参数类型&#39;PFObject&#39; - Swift: Cannot convert value of type '() -> Bool' to expected argument type 'PFObject' 无法将类型()的值转换为预期的参数类型bool(Swift)? - Cannot convert value of type () to expected argument type bool (Swift)? &#39;无法将&#39;Int&#39;类型的值转换为预期的参数类型&#39;CGPoint&#39; - 'Cannot convert value of type 'Int' to expected argument type 'CGPoint' 无法在Swift 3中将字符串类型的值转换为预期的参数类型int - cannot convert value of type string to expected argument type int in swift 3 无法将 Int 类型的值转换为预期的参数类型“...” - Cannot convert value of type Int to expected Argument type '...'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM