Open huming0618 opened 7 years ago
class Animal {}
class Cat: Animal {}
let cat = Cat()
let animal = cat as Animal
let num1 = 42 as CGFloat
let num2 = 42 as Int
let num3 = 42.5 as Int
let num4 = (42 / 2) as Double
switch animal {
case let cat as Cat:
print("如果是Cat类型对象,则做相应处理")
case let dog as Dog:
print("如果是Dog类型对象,则做相应处理")
default: break
}
class Animal {}
class Cat: Animal {}
let animal :Animal = Cat()
let cat = animal as! Cat
let animal:Animal = Cat()
if let cat = animal as? Cat{ print("cat is not nil") } else { print("cat is nil") }
Refer
http://www.cnblogs.com/gongyuhonglou/p/5919908.html
Learn the swift and ios developing