Swift_继承
2017-03-03 16:10
120 查看
Swift_继承
点击查看源码func testInheritance() { //基类 class Base { var count = 0.0 var description: String { return "count:\(count)" } //可继承 func inherited() { } //防止继承 final func preventing() { //如果不想子类继承 可在类 属性或方法前添加final } } //子类 class Subclass: Base { //继承的属性和方法前都有override override var count:Double { didSet { print("\(#function)") } } override var description: String { return "\(#function)" + super.description } override func inherited() { print("\(#function)") } } let subclass = Subclass() subclass.count = 10 print("\(subclass.description)") subclass.inherited() /* print count descriptioncount:10.0 inherited() */ }
相关文章推荐
- Swift - 继承UIView实现自定义可视化组件(附记分牌样例)
- [Swift]继承
- Swift高级开发语言--枚举,继承,协议,扩展
- Swift2.0(12)继承与多态
- Swift 继承
- swift继承
- 23、swift开发iOS——继承
- swift中构造器的自动继承
- 窥探Swift之类的继承与类的访问权限
- Swift_继承
- Swift 中的静态方法继承
- Swift项目中不能定义OC类继承Swift类
- swift学习笔记之-继承
- swift可以不继承NSObject
- 初学swift笔记 继承(十)
- Swift继承(Inheritance)
- Swift学习——类的定义,使用,继承,构造等(五)
- Swift学习笔记(十一)继承
- Swift 之类的继承与类的访问权限
- swift继承