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

Josh Patko
Josh Patko
1,478 Points

How do I add a designated initializer to the Button class?

Assume we are creating the user interface for an app and we need to create a class to represent a Button. Below you will find the basic definition for the Button class. Add a designated initializer to it. Remember to provide initial values for all stored properties without default values.

Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

Would be something like this?

Button *roundButton = [[Button alloc] init];

3 Answers

Andy's answer is this forum thread may be helpful:

https://teamtreehouse.com/forum/init-error

class Button {
  var width: Double
  var height: Double

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

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