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.

Theo VOGLIMACCI
8,027 PointsCan't finish this challenge
Hello,
Please could you explain me in details how to finish this challenge?
My class seems good, but i don't know how to make the init method in it.
class Shape {
var numberOfSides: Int = 0
init() {
self.numberOfSides = numberOfSides
}
}
let someShape = Shape
2 Answers

Daniel Santos
34,969 PointsAs you pointed, there is a problem in your init method. If you look closely, you are trying to assign self.numberOfSides = numberOfSides
. But where is the numberOfSides
coming from? Remember, you should get this as an argument. For example:
class Person {
let firstName: String
let lastName: String
init(firstName: String, lastName: String) {
self.firstName = firstName // I am getting this firstName from the argument above
self.lastName = lastName // Same thing here.
}
}
I made an example with a different class just to stimulate your brain, but if you still stuck please let me know.
-Dan

Theo VOGLIMACCI
8,027 PointsWell much thanks Daniel,
Here is the full answer if someone needs help aswell.
// Enter your code below
class Shape {
var numberOfSides : Int
init(numberOfSides: Int) { //as you mentioned I forgot to declare NumberOfSides as an argument in the init method
self.numberOfSides = numberOfSides
}
}
let someShape = Shape(numberOfSides: 4)

Daniel Santos
34,969 PointsYou are welcome!