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?

Ricardo Gonzalez
Ricardo Gonzalez
2,286 Points

What does it mean by instance?

Forgot what an instance is so can someone help?

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.0

  }
 }
Gary Calhoun
Gary Calhoun
10,317 Points

I think an instanced object or variable is a clone copy and if the original changes the instanced clone version changes as well. I am not 100 percent sure though.

Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

Gary, just thought I might tell you that if you want to answer a question you should post it as an answer vs. a comment. One reason is because you can get up-voted and marked as best answer on answers, but not comments.

Gary Calhoun
Gary Calhoun
10,317 Points

Oh thank you I see the section now I have to scroll down to the answer section lol

Greg Kitchin
Greg Kitchin
31,522 Points

I've not done the IOS course, but in general, an instance is a working object, that is derived from a class. You can imagine the class as a cookie cutter, that has it's own characteristics, and when you want a cookie (the instance), you create one, using the cutter as a template.

1 Answer

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

First, the challenge won't let you pass if the class you create is inside the first one so you need to move it out; second, instance is simply creating a variable or constant and giving it a value, like this:

var rounded = RoundButton(width: 4.0, height: 2.0)

Happy coding!