//Swift 简单继承和动态扩展
class Hello {
var _name: String? = "Swift"
init(name: String) {
_name = name
}
init() {
}
func sayHello() {
println("Hello \(_name)")
}
class func sayHi(){
println("Hi")
}
}
class Hi: Hello {
override func sayHello() {
super.sayHello()
println("Hi \(_name)")
}
}
//动态扩展方法
extension Hi {
func sayHaha() {
println("Hana")
}
}
var hi = Hi()
hi.sayHello()
hi.sayHaha()
//也可以为自定义类起别名
typealias Hii = Hi
var hii = Hii()
hii.sayHaha()
Swift 简单继承和动态扩展
最新推荐文章于 2018-09-19 16:47:00 发布