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 trialHamza Ahmad
3,061 Pointsnot working on my Xcode?
Assignment
Create a base class called Shape which will have 2 properties: sides and name Create a subclass called Square, it will also have 2 properties called: sideLength and area. The area property will be a computed property with getter and setter methods. Add a designated initializer to Square which accept all three properties: sides, name and sideLength Add a convenience initializer to Square that will accept only the sideLength and provide default values. 4 for sides and βSquareβ for name Create an instance of Square using the convenience initializer?
MY Answer same as shown in the video by Amit.
class Shape { let side: Int let name: String
init (side: Int, name: String){
self.side = side
self.name = name
}
}
class Square: Shape { var sideLength: Double = 0.0 var area: Double = 0.0 {
get {
return sideLength * sideLength
}
set {
sideLength = sqrt(newValue)
}
}
init(name: String, side: Int, sideLength: Double){
self.sideLength = sideLength
super.init(sides: sides, name: name)
}
convenience init(sideLength: Double) {
self.init (name: "square", side: 4, sideLength: sideLength)
}
}
let square = Square(sideLength: 20) square.name square.side square.sideLength square.area square.area = 100 square.sideLength
still getting error at two stages -->
1)
super.init(sides: sides, name: name)
error = use of unresolved identifier
2)
var area: Double = 0.0 {
error = cannot call vale of non-funtional type???