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 trialJustin Henderson
4,340 PointsI don’t seem to be getting the “class definition” portion of this challenge?
I have a good idea based on the Swift documentation but I’m not sure how to go about properly setting up my class definition & initializer method?
// Enter your code below
class Shape {
var numberOfSides: Int
init(){
}
}
2 Answers
kjvswift93
13,515 Pointsclass Shape {
var numberOfSides: Int
init(sides: Int) {
self.numberOfSides = sides
}
}
let someShape = Shape(sides: 4)
Mascuud Musse
314 Points@ Justin Henderson what you've done is you've created a shape class which is correct but in the init method you've not set it up properly. What your meant to do is something like this
init(numberOfSides: Int){ self.numberOfSides: numberOfSides }
What you've done with your code is you've created an initialiser method that has done nothing with the numberOfSides property on the Shape Object and this will get you into an error, the way you've written it is such a way that your assuming the numberOfSides has a value already assigned to it which it hasn't. I hope you understand if any more help please ask.
Justin Henderson
4,340 PointsJustin Henderson
4,340 PointsKyle,
Thank you for the response this was very helpful. After going through it a few times I finally got it! Thanks again.