Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Object-Oriented Swift Class Inheritance Overriding Properties

Niilo Pirttijärvi
PLUS
Niilo Pirttijärvi
Courses Plus Student 2,354 Points

I don't understand why some things are done in the tutorial?

override init(x: Int, y: Int){
    super.init(x: x, y: y)
}

I don't understand why the super.init(x: x, y: y) part was needed. I understand how and why the override is used but not what the super.init part here is doing?

1 Answer

Jari Koopman
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jari Koopman
Python Web Development Techdegree Graduate 29,349 Points

Hi Niilo,

Because you're overriding the init from a superclass, you have to first initialise the superclass, before you can start doing things for the subclass. More info on subclassing can be found in the docs under Initializer Inheritance and Overriding

Hope this helped,

Regards, Jari