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 trialJosh Patko
1,478 PointsHow 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.
3 Answers
james white
78,399 PointsAndy's answer is this forum thread may be helpful:
MUZ140316 Milton Chitsike
7,344 Pointsclass Button {
var width: Double
var height: Double
init(width:Double, height:Double){
self.width = width
self.height = height
}
}
ellie adam
26,377 Pointsclass Button {
var width: Double
var height: Double
init(width:Double, height:Double){
self.width = width
self.height = height
} }
Caleb Kleveter
Treehouse Moderator 37,862 PointsCaleb Kleveter
Treehouse Moderator 37,862 PointsWould be something like this?
Button *roundButton = [[Button alloc] init];