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?

Aaron Anderson
Aaron Anderson
2,541 Points

wth is wrong with this code?

I need a fresh pair of eyes to look at this... am I missing something? I have no errors in the compiler

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 = 5
  }
}
var rounded = RoundButton(width: 5, height: 5)

2 Answers

Jhoan Arango
Jhoan Arango
14,575 Points

Hi Aaron:

I’d like to give you the full answer to your challenge, BUT I think you may have an idea of what you are doing, the only thing is that you are making a common mistake on this one. I say common, because in the coding world, placing brackets in the wrong position can drive you crazy and not know what is going on.

Now with that said I will give you a hint of what’s wrong with your code, and this may help you get to your problem. If you still can’t find the problem please let me know so that I can help you further. I try to do it this way, because it helps a lot more to work hard and solve it yourself than to just have someone give you the answers, to your challenges.

Hint: Closing Bracket

Hope it helps, I’d like to know if you did solve it or not.

Rashii Henry
Rashii Henry
16,433 Points

Whenever you have errors with your code in the treehouse compiler. Try copying the code into a playground and hopefully the compiler will be able to catch the error. if neither of the compilers (Treehouse or Xcode) complain, then try asking your question again on the forum. On the good note, that's some pretty sweet code you have there!