我想使用点语法得到布尔值的反义词。
例如
let digitsExceptForFive = [1, 2, 3, 4, 6, 7, 8, 9]
let fives = [1, 2, 3, 4, 5, 6, 7, 8, 9].filter(!digitsExceptForFive.contains)
// Cannot convert value of type '(Int) -> Bool' to expected argument type 'Bool'
但是,以下代码有效。
let digitsExceptForFive = [1, 2, 3, 4, 6, 7, 8, 9]
let notFives = [1, 2, 3, 4, 5, 6, 7, 8, 9].filter(digitsExceptForFive.contains)
// [1, 2, 3, 4, 6, 7, 8, 9]
我需要使用 not 运算符在功能上获得相反的值。如果可能的话,我不想为此定义一个布尔扩展或自定义运算符。
你怎么能在 Swift 中做到这一点?