Why with Xcode 12.2 beta 3 in playground keypath as func do not compile?

So I was trying out the code from here and got error:

error: cannot convert value of type 'WritableKeyPath<_, _>' to expected argument type '(Bool) -> Bool'**
error: cannot infer key path type from context; consider explicitly specifying a root type

My Playground
let (switch1, switch2, switch3, switch4) = (true, true, false, false)
let switches = [switch1, switch2, switch3, switch4]
let isOn = !switches
    .filter(\.self)     // error here
    .isMultiple(of: 2)

It’s a known bug: SR-12897

1 Like

Just use .filter { $0 } for now.

1 Like
Terms of Service

Privacy Policy

Cookie Policy