After run following code in playgroud, why x value is 2? Is there anything wrong with swift generic type and "is" operator? class Item {}
class Campaign: Item {}
class AdGroup : Item {}
class A<T: Item> {
func val() -> Int{
let item = T()
if item is Campaign {
return 1
} else {
return 2
}
}
}
var m = A<Campaign>()
let x = m.val()
来源:https://stackoverflow.com/questions/27899744/wrong-generic-type-in-swift