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 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!