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

iOS

Getter & Setter Method Final Exam Practice - Compile Error

I already know the answer to the Final Exam but am having an issue (still) with a compile error that says: Cannot assign to 'sides' in 'self'. This is exactly how Amit writes the code in the video. Any assistance is greatly appreciated

class Shape {
    let sides = Int
    let name = String

    init(sides: Int, name: String) {
        self.sides = sides
        self.name = name
    }
}

No need to answer, I figured it out. I should have been using the colon instead of equal sign.

1 Answer

I know you already have the answer, but I will put an answer on here for those that may be having the same issue.

class Shape {
    let sides : Int // you had the equal sign that assigns a value. Instead you should use colons to declare a type
    let name : String

    init(sides: Int, name: String) {
        self.sides = sides
        self.name = name
    }
}