iOS Object-Oriented Swift Class Inheritance Creating a Subclass

Elena Iliasova
Elena Iliasova
iOS Development with Swift Techdegree Student 1,739 Points

please tell me what is wrong with my code?

please tell me what is wrong with my code?

class Vehicle {
  var numberOfDoors: Int
  var numberOfWheels: Int

  init(withDoors doors: Int, andWheels wheels: Int) {
      self.numberOfDoors = doors
      self.numberOfWheels = wheels
class Car: Vehicle {
var numberOfSeats: Int 
init(numberOfDoors: Int, numberOfWheels: Int, numberOfSeats: Int) {
self.numberOfSeats = numberOfSeats
super.init(numberOfDoors: doors, numberOfWeels: wheels)
let someCar = Car(numberOfDoors: 4, numberOfWheels: 2, numberOfSeats: 4)

// Enter your code below

1 Answer

Steven Parker
Steven Parker
207,983 Points

The labels in the "super" call need to match the parameters and parent labels, and the class was missing a closing brace.

Brace matching is easier to spot if you consistently use indentation to indicate nesting level.

    // labels need to match
    super.init(withDoors: numberOfDoors, andWheels: numberOfWheels)
}   // closing brace was missing