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 Object-Oriented Swift Classes in Swift Instances of Classes

Martel Storm
Martel Storm
4,157 Points

Object-Oriented Swift 3 Instances of classes Stuck on code challenge

I'm stuck yet again on another code challenge. I'm a super noob!

It would be nice if the answers to all these challenges were posted and organized chronologically somewhere so instead of asking for help on almost every challenge I could study the correct answer.

Just gonna keep on truckin! Love how helpful the community has been thus far!

Per usual if you have any general tips or words of motivation that would also be very much appreciated!

objects.swift
// Enter your code below
class Shape {
var numberOfSides: Int
init (Shape: Int) {
self.Shape = Shape
}
struct someShape {
let someShape = someShape.Shape
}
}

1 Answer

Dan Lindsay
Dan Lindsay
39,611 Points

Hey Martel,

You are close on this one. You have tried to init on the class Shape, instead of the property numberOfSides OF the class Shape. Also, you created a struct instead of just the constant someShape. The code below should work fine.

class Shape {
    var numberOfSides: Int

    init(numberOfSides: Int) {
        self.numberOfSides = numberOfSides
    }
}

let someShape = Shape(numberOfSides: 4)

In terms of general tips, I would encourage you to work on the challenge in an Xcode Playground, as you will have code completion on your side to help guide the way. I remember when I first started learning to code, I would watch the videos several times, and then a week or so later, I would come back to the course and just try all the code challenges and see what I retained. It seems like you already have a positive attitude, which is awesome for sure! That will always help a lot. Keep on trucking and I hope this helps you out.

Dan

Martel Storm
Martel Storm
4,157 Points

I'm impressed by how clearly you were able to explain what I was doing wrong in a single sentence. Thank you!