Swift 2.0 Learning Notes (Day 42)-constructor call rules

Source: Internet
Author: User

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

  •  

  • convenience constructors must call other constructors defined in the same class 。 person

  • 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.