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

My code here seems (to my eyes) to be correct. What am I missing?

I can't figure this one out.

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){
    width += points
    height += points
  }
}

Never mind, I realized that as I was following along, my version of Xcode for some reason rejects the necessity of the " _ " inserted in the override function.

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

The argument passing is missing the little _ underscore, other than that, your code is fine

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

Thank you William. Do you know why Xcode 7.0 beta 4 doesn't seem to like having an underscore there? It's telling me that percentage has no keyword name, making the _ extraneous.

William Li
William Li
Courses Plus Student 26,868 Points

Hi, S Willsea, I'm only using final release of Xcode on my machine, but given how young Swift is and Apple has been actively pushing breaking changes to the language, I wouldn't be surprised if that's the case.

Very good, thank you William.

Josue Gisber
PLUS
Josue Gisber
Courses Plus Student 9,332 Points

Its because Xcode 7.0 use other version of swift. You should use final release of Xcode 6.4 because thats the one that works with the version of swift teach at the corse.