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 trialMarinos Isaakidis
1,199 PointsFirst of all i can not call sqrt at newValue???????? Secondly i cant call the convenuence init ???
class Shape {
var sides : Int
var name : String
init(sides : Int,name : String) {
self.sides = sides
self.name = name
}
}
class Square: Shape {
var sideLength : Double
var area : Double {
get {
return sideLength * sideLength
} set {
sideLength = newValue // here i cant insert sqrt????
}
}
init(sides : Int , name : String , sideLength : Double) {
self.sideLength = sideLength
super.init(sides: sides, name: name)
}
convenience init(sideLength : Double) {
self.init(sides : 4 ,name : "Square", sideLength : sideLength)
}
}
var tshirt = Shape(sides: 4, name: "Square") // i cant call the convenience
2 Answers
Steve Hunter
57,712 PointsHi Marinos,
I don't understand what your question is, unfortunately. Is this to do with a code challenge or part of a video?
You've mentioned the convenience initializer not working - what error are you getting? Also, where you've commented that the convenience initializer isn't working is a piece of code creating a new Shape
object. The convenience initializer in your code is within the Square
class which inherits from Shape
. But Shape
doesn't have a convenience initializer. That said, the code works fine in my Playground.
What error are you seeing or what doesn't work as you think it should? It all works OK for me - I can create an instance of Square
using either the convenience or other initializer.
Let me know what's not working for you and we'll get to the bottom of that.
Steve.
Marinos Isaakidis
1,199 PointsHi Steve
First of all i want to thank you for your response. This is at the final Exam at swift. With your help i have already solve my issues.It was to easy. first i was writing sqtr and the error was "use of unresolved identifier" and of course is sqrt!!!!!!!!!!!! and also i was calling the Shape and not the Square class..Stupid errors
Thank you very much for your reply.
Steve Hunter
57,712 PointsNo problem - I'm glad you got it sorted.
Steve.