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 2.0 Classes Instances of Classes

Where did I got wrong. OMG!! ; - ;

Please help! ; - ;

classes.swift
// Enter your code below

class Shape(){
var numberOfSides: Int
init(numberOfSides: Int){
self.numberOfSides = numberOfSides
}
}

let someShape = Shape()

I'm having the same problem. What's wrong with my code?

class Shape { 

    var numberofSides: Int 

 init() {
    self.numberOfSides = numberOfSides 
          } 
                 } 

let someShape = Shape()

sugabelly, you've got a capitalization error on the numberOfSides property. Tiny typos can cause cause big headaches! :confounded:

1 Answer

Hi Kawal,

Two small issues with your code:

  1. When declaring a class, you don't need opening and closing parentheses. This isn't a function, and we're not creating a class instance.
  2. When you do create an instance of Shape, you have to use the initializer you just created, which takes one argument - an integer for the number of sides.

I think you can take it from here!

Cheers :beers:

-Greg

Fixed! Yay!

But Seriously man, Object Oriented Programming is pretty confusing. Especially when we are declaring so many values etc. There should be some analogy to make it easier.

It's hard to wrap your head around, for sure! You'll get it though. Keep working on it!