1
protocol A { }
class B: A { }
func f(x: Any) {
print(x is A)
}
let x: B? = B()
f(x: x) // false
Ich würde erwarten, dass dies stattdessen true
ist. Ist es ein Fehler in Swift?Swift Beliebiges Methodenargument Protokollkonformität Verloren
Die folgenden Beispiele funktionieren und das Rück true
:
// 1
func f(x: Any) {
print(x is A)
}
let x: B = B() // not optional
f(x: x) // true
// 2
func f(x: Any) {
print(x is B) // check for B
}
let x: B? = B()
f(x: x) // true
Yup, [dies ist ein Fehler] (https://bugs.swift.org/browse/SR-6279). – Hamish