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 Complex Data Structures Instance Methods

Instance Methods

In this vide at 4:30, you said "We automatically get a method with parameters for the stored properties in our class" when you tried to create coordinatePoint2 and xcode provided an autocomplete. As you were trying to create a constant with type Point, are you implying that the Struct is a method because the underlying Struct form is a function?

2 Answers

Nathan Tallack
Nathan Tallack
22,159 Points

So that autocomplete stuff that shows when you are creating an object from a class (or struct or any other kind of type like this) is actually from one (or more) initializer methods.

Initializer methods are methods that are named init of which you can have more than one inside your type so that you can support different parameters coming in.

In the case in this video, your type did not have a method named init created. But the compiler, using that magic he mentions, has a "automatic" initializer in this case that it creates from the properties in your method.

This allows you to pass parameters in when you are creating a new object from your type and it will assign the values of these parameters to your properties (of the same name) inside the object as it is created.

Later you will learn to create your own init methods. That is lots of fun. :)

cool thanks for the answer!!!