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
Alexandre Perron
4,410 PointsCode Final Assignment : Object Oriented Swift
Hello, here is my code for the final assignment for Object Oriented Swift. It says in my setter for the Square subclass that I cannot assign SideLength to itself. Isn't that what I'm supposed to do when initializing? Thank you
class Shape {
let sides: Int
let name: String
init(sides: Int, name: String) {
self.sides=sides
self.name=name
}
}
class Square: Shape {
let sideLength : Double //Let
var area: Double { //Computed thus VAR
get {
return sideLength * sideLength
}
set {
sideLength = sqrt(newValue)
}
}
init(name: String,
sides: Int,
sideLength: Double) {
self.sideLength = sideLength
super.init(sides: sides, name: name)
}
convenience init(sideLength: Double) {
self.init(name: "Square", sides: 4, sideLength: sideLength)
}
}
2 Answers
Marcel Krause
6,748 PointsThe only thing you'd have to change is let sideLength: Double to var sideLength: Double and your code should work.
Alexandre Perron
4,410 PointsCheers thanks for taking the time! It worked!