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 Inheritance Overriding Methods

Michael Watson
Michael Watson
1,822 Points

I've written out an override method that looks to be good, and behaves itself in XCode. Getting a syntax error here.

Am I missing something obvious?

Button.swift
class Button {
  var width: Double
  var height: Double

  init(width:Double, height:Double){
    self.width = width
    self.height = height
  }

  func incrementBy(points: Double){
    width += points
    height += points
  }
}

class RoundButton: Button {
  var cornerRadius: Double = 5.0
  override func incrementBy(points: Double = 7.0) {
  }
}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Well it may not be obvious but remember that you're overriding something. It's going to send in some points and no matter what it sends in... we're going to override that with 7.0. So this is what the challenge is looking for.

class RoundButton: Button {
  var cornerRadius: Double = 5.0
  override func incrementBy(points: Double) {
    width += 7.0
    height += 7.0
  }
}
Michael Watson
Michael Watson
1,822 Points

Thanks. That's odd because it does state "default to 7.0" rather than "always override to 7.0". Maybe I'm misreading it.