Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Object-Oriented Swift Value vs Reference Types Final Challenge

becky hayes
becky hayes
2,226 Points

Really struggling on this..

I've got the first part ok (i.e. the vehicle class) but when creating the sub class i'm not sure how to fix the car's properties (doors / wheels) at 4.

Vehicle.swift
class Vehicle {
    let wheels: Int
    let doors: Int

    init(wheels:Int, doors:Int){
    self.wheels = wheels
    self.doors = doors

    }
}

class Car: Vehicle {
    let carWheels: Int = 4
    let carDoors: Int = 4
    // A car mu let wheels: Int

    override.func init(wheels: Int, doors: Int){
      // call super.init
    }
}

1 Answer

Keli'i Martin
Keli'i Martin
8,227 Points

So one of the errors you would have gotten at the start of the challenge was that the Car class's init() was not calling super.init(). super.init() is just the initializer for the parent class. And what are the parameters for the Vehicle class's init()?

Also, don't forget when calling super.init() to include the names of the parameters in the call.

Hope this helps!