A little bit of a problem with Swift class inheritance

Source: Internet
Author: User

Others have written a lot about the Swift class inheritance, here I just to add a little rookie tutorial inheritance on no materializing description of things, rookie tutorial about class-inherited sites: http://www.runoob.com/swift/swift-inheritance.html

On this issue, another blog post also wrote this:

http://blog.csdn.net/binglan520/article/details/52662815

All of the attributes in the parent class can be defined without giving the initial value, the value is given in the Init function, and the properties of the subclass must be given the initial value at the time of definition, or the INIT function will give an error.

The example code is as follows:

Class father{   var valuefather:int//There is no assignment     init{     valuefather = 0;    }}
Class child{   var valuechild:int   //There is no assignment, compile will error   init{       super.init ();       Valuechild = 1;   }  }

The right subclass should be

Class child{   var valuechild:int  = 0//There is no assignment, compile will error   init{       super.init ();       Valuechild = 1;   }  }

The type of error is: Property ' Self.valuechild ' isn't initialized at Super.init call

A little bit of a problem with Swift class inheritance

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.