Bummer! You must be logged in to access this page.

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

Type methods: Why don't you need an init() method with type classes? (I thought it was required with reference types)

Example:

class Calculator {
  class func squarRoot(value: Double) -> Double {
     return sqrt(value)
  }
}

1 Answer

In the case of a class that does not have any stored properties, there is no need for an init() method as you have nothing to initialize. The purpose of the method is to guarantee that all stored properties have a value at the time of creation.

Therefore, no properties, no init :]

Side note, if a stored property is initially given a value, you are also not required to provide an init()

Example:

class Calculator {
    var text: String = ""

    class func squareRoot(value: Double) -> Double {
        return sqrt(value)
    }
}