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.

iOS Object-Oriented Swift Value vs Reference Types Final Exam - Solution

First 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

Hi 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.


Hi 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.

No problem - I'm glad you got it sorted.