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 Classes and Objects Designated Initializer

Rakeem Williamson
Rakeem Williamson
7,163 Points

cant pass the code challenge

class Button { let width: Double let height: Double } class Button { let width: Double let height: Double

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

1 Answer

Josh Rosenzweig
Josh Rosenzweig
2,779 Points

Hi Rakeem, You are actually very close, there are just a few syntax errors in your code. 1st, each class needs to contain parentheses for accepting parameters, even if there are none. [ class Button(){} ]

2nd, you placed the parameters within the class brackets ( {} ) when it should be within the parentheses at the beginning of the class after the name of the class is given. [ (width: Double, height: Double) { } ]

But, aside from those mistakes your code is almost correct, if you are still confused it should look like this instead:

class Button (width: Double, height: Double) {

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

I hope this helps you out

Josh Rosenzweig
Josh Rosenzweig
2,779 Points

My pleasure, I'm glad it worked out!