original articles, welcome reprint. Reprint Please specify: Dongsheng's blog
You can use the constructor proxy in a constructor to help complete some of the construction work. Class constructor proxies are divided into horizontal and upward proxies, which can only occur inside the same class, and this constructor is called a convenience constructor. An up-agent occurs in the case of inheritance, in which the parent class constructor is called to initialize the stored property of the parent class, which is called the specified constructor, during the child class construction.
Constructor Call rules
Person and Student Class Example: class Person { var name:string var age:int func description (), String { return " \ (name) is: \ (age) " } Convenience init () { //facilitation Constructor Self.init (name:" Tony ") self.age = }< C10/>convenience Init (name:string) {//Facilitation constructor Self.init (Name:name, age:18) } init (name:string, age:i NT) { //Specify constructor self.name = name Self.age = Age }} class Student:person { var school: String Init (name:string, Age:int, school:string) { //Specify constructor Self.school = School super.init ( Name:name, Age:age) } convenience override init (name:string, Age:int) {//Facilitation constructor Self.init (Name:name, Age:age, School: "Tsinghua University")
Calls between constructors form a chain of constructor functions.
S Wift 3
person
Welcome to follow Dongsheng Sina Weibo@tony_Dongsheng.
Learn about the latest technical articles, books, tutorials and information on the public platform of the smart Jie classroom
?
More ProductsIOS,Cocos, mobile Design course please pay attention to the official website of Chi Jie Classroom:http://www.zhijieketang.com
Smart-Jie Classroom Forum Website:http://51work6.com/forum.php
Swift 2.0 Learning Notes (Day 42)-constructor call rules