Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
  }
}
ellie adam
ellie adam
26,376 Points
class Button { 
var width: Double
var height: Double

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