swift继承
2017-03-10 15:44
176 查看
A class can inherit methods, properties, and other characteristics from another class. When one class inherits from another, the inheriting class is known as a subclass, and the class it inherits from is known as its superclass. Inheritance is a fundamental behavior that differentiates classes from other types in Swift.
一个类可以从其他类继承属性和其他的特性。当一个类继承于另一个类时,它叫做子类,自己继承的那个类叫做父类。继承是类和其他类型不同的基础。
Classes in Swift can call and access methods, properties, and subscripts belonging to their superclass and can provide their own overriding versions of those methods, properties, and subscripts to refine or modify their behavior. Swift helps to ensure your overrides are correct by checking that the override definition has a matching superclass definition.
在swift中,类可以调用和访问属于父类的方法,属性,附属脚本。也可以重写这些方法属性来改善和修改它们的行为。swift会帮助确保你的重写行为是正确的,通过检查匹配的父类。
Classes can also add property observers to inherited properties in order to be notified when the value of a property changes. Property observers can be added to any property, regardless of whether it was originally defined as a stored or computed property.
类也有属性观察机制。
基类
Any class that does not inherit from another class is known as a base class.
任何不继承自其它类被称为基类。
Swift classes do not inherit from a universal base class. Classes you define without specifying a superclass automatically become base classes for you to build upon.
swift的类不继承于一个通用的基类。你定义一个类不指定父类的话将会自动变成基类。
子类
Subclassing is the act of basing a new class on an existing class. The subclass inherits characteristics from the existing class, which you can then refine. You can also add new characteristics to the subclass.
子类是基于父类,子类从已经存在的类继承特性。并且你可以优化改善它。你也可以为子类添加新特性。
To indicate that a subclass has a superclass, write the subclass name before the superclass name, separated by a colon:
为了表明子类继承自父类,写子类的名字在父类前面用冒号分割。
一个类可以从其他类继承属性和其他的特性。当一个类继承于另一个类时,它叫做子类,自己继承的那个类叫做父类。继承是类和其他类型不同的基础。
Classes in Swift can call and access methods, properties, and subscripts belonging to their superclass and can provide their own overriding versions of those methods, properties, and subscripts to refine or modify their behavior. Swift helps to ensure your overrides are correct by checking that the override definition has a matching superclass definition.
在swift中,类可以调用和访问属于父类的方法,属性,附属脚本。也可以重写这些方法属性来改善和修改它们的行为。swift会帮助确保你的重写行为是正确的,通过检查匹配的父类。
Classes can also add property observers to inherited properties in order to be notified when the value of a property changes. Property observers can be added to any property, regardless of whether it was originally defined as a stored or computed property.
类也有属性观察机制。
基类
Any class that does not inherit from another class is known as a base class.
任何不继承自其它类被称为基类。
Swift classes do not inherit from a universal base class. Classes you define without specifying a superclass automatically become base classes for you to build upon.
swift的类不继承于一个通用的基类。你定义一个类不指定父类的话将会自动变成基类。
子类
Subclassing is the act of basing a new class on an existing class. The subclass inherits characteristics from the existing class, which you can then refine. You can also add new characteristics to the subclass.
子类是基于父类,子类从已经存在的类继承特性。并且你可以优化改善它。你也可以为子类添加新特性。
To indicate that a subclass has a superclass, write the subclass name before the superclass name, separated by a colon:
为了表明子类继承自父类,写子类的名字在父类前面用冒号分割。
相关文章推荐
- 23、swift开发iOS——继承
- iOS讲解迷惑--Swift中枚举、继承、协议
- swift中构造器的自动继承
- IOS开发语言Swift入门连载---继承
- Swift_继承
- [swift]初始化方法自动继承
- 苹果新的编程语言 Swift 语言进阶(十)--类的继承
- Swift 继承
- swift继承和扩展
- Swift难点-继承中的构造规则实例详解
- Swift项目中不能定义OC类继承Swift类
- Swift学习- 继承(十三)
- Swift2.1 语法指南——继承
- swift 继承相关
- 在Swift中使用Objective-C编写类、继承Objective-C类
- Swift -- 8.1 继承
- Swift继承的用法
- Swift入门教程11-继承
- 13.8 Swift构造方法的自动继承
- 【swift】15-0610 下标 继承和扩展 初始化和反初始化