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!

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 2.0 Class Inheritance Creating a Subclass

too much error

swift_lint.swift:15:1: error: expected declaration super.init(withDoors doors:Int,andWheels wheels:Int) ^ swift_lint.swift:15:7: error: consecutive declarations on a line must be separated by ';' super.init(withDoors doors:Int,andWheels wheels:Int) ^ ; swift_lint.swift:16:1: error: expected declaration self.numberOfSeats = 4 ^ swift_lint.swift:15:7: error: overriding declaration requires an 'override' keyword super.init(withDoors doors:Int,andWheels wheels:Int) ^ override swift_lint.swift:7:5: note: overridden declaration is here init(withDoors doors: Int, andWheels wheels: Int) { ^ swift_lint.swift:15:7: error: invalid redeclaration of 'init(withDoors:andWheels:)' super.init(withDoors doors:Int,andWheels wheels:Int) ^ swift_lint.swift:14:10: note: 'init(withDoors:andWheels:)' previously declared here override init(withDoors doors:Int,andWheels wheels:Int) ^ swift_lint.swift:14:10: error: initializer requires a body override init(withDoors doors:Int,andWheels wheels:Int) ^ swift_lint.swift:18:18: error: incorrect argument labels in call (have 'numberOfDoors:numberOfWheels:', expected 'withDoors:andWheels:') let someCar = Car(numberOfDoors:2,numberOfWheels:4) ^~~~~~~~~~~~~~ ~~~~~~~~~~~~~~ withDoors andWheels

class Vehicle {
    var numberOfDoors: Int
    var numberOfWheels: Int
    var numberOfSeats: Int
    init(withDoors doors: Int, andWheels wheels: Int) {
        self.numberOfDoors = doors
        self.numberOfWheels = wheels

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

2 Answers

Moritz Lang
Moritz Lang
25,909 Points

Why do you want to override the initializer? Because numberOfSeats has a default value there is no need to add one. The task on this challenge is much simpler:

class Car: Vehicle {
    var numberOfSeats = 4

let someCar = Car(withDoors: 5, andWheels: 4)