func check (num: Int, arr: Array<Any>) -> Bool {
if arr.contains(where: num) {
return true
}
}
check(num: 7, arr: [1, 4, 7, 25, 99])
// eror: Cannot convert value of type 'Int' to expected argument type '(Any) throws -> Bool'
You are doing lot of incorrect coding in the above question. So it is better to take a look at here -> Functions in Swit .
[DataTpye]
signature.Corrected version
func check (num: Int, arr: [Int]) -> Bool {
return arr.contains(num)
}
print(check(num: 7, arr: [1, 4, 7, 25, 99])) // true
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.