简体   繁体   中英

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 :

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:

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM