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 What is Inheritance?

Laura Morgan
Laura Morgan
1,941 Points

Trouble with the Inheritance challenge in the Object-Oriented Swift section. It says it isn't compiling...

"Create an instance of the class RoundButton and name the instance rounded."

I am having trouble and going in circles on this challenge. It says that it isn't compiling, but there is nothing in the editor and when look at it in the playground I don't get any errors. I just added the 5 's to test it out, but I guess I am pretty confused. :|

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

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

class RoundButton: Button {
var cornerRadius: Double = 5.0

var rounded = RoundButton(width: 5.0 , height: 5.0)

}

2 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Laura,

Simple fix. You need to create your instance of RoundButton outside the class definition:

class Button {
  var width: Double
  var height: Double

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

class RoundButton: Button {
  var cornerRadius: Double = 5.0
}

var rounded = RoundButton(width: 5.0 , height: 5.0)