Swift type inference and type checking issue
问题 I'm not looking for an answer like how to do it correctly but why this happens. Here is the code: func isInt(param: AnyObject?) { if let value = param as? Int { print(value) } else { print("Not Int") } if let value = param { if value is Int { print(value) } else { print("Not Int") } } } let a:AnyObject? = 1.2 let b:Float? = 1.2 let c:Double? = 1.2 isInt(a) isInt(b) isInt(c) I understand in the first if loop, the param is casted to Int and then print out 1 . But why in second if loop, if value