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 Introduction to Classes

Classes, Instances, Methods, Self and Initialisers....Do my head in! Structs are okay...

I don't understand how init and self really work, and instances and methods I don't get how you would know to do point.otherpoint = Int or whatever.

Creating Classes and using Structs I get, but its really hard to understand how all the other stuff works and when to use the dot notation. can someone clearly explain how this all works?

Anthony c
Anthony c
20,907 Points

The choice of example (a game using coordinates, moving enemies, etc.) was just not good for an introduction class. It would have been better to teach class/struct/etc. using a simple CRUD example of a blog post. The current examples forces students to wrap their heads around more subject matter before they can even start to think about the core lesson of the courses (classes and structs).

Steven Beckham
Steven Beckham
2,010 Points

I'm glad to know it's not just me. I've followed pretty well up to this point but in this lesson I was just copying code off the screen without any comprehension of what its means.

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Heath Robertson,

I would check out The Swift Programming Language Guide. Check out the chapters on Classes and Structures, Methods, Properties, Initialization, Subscripts, and Inheritance. It's a lot of material but it's really an invaluable resource on these subjects.

Classes and Structures: These are flexible data structures that you use as building blocks for your code. They are blueprints that you use to create objects. They define what an object will look like (what methods and properties it has).

Instances: An instance is basically an object. It's best understood how it relates to classes. If your class is a blueprint or model of something, when you actually create something from that blueprint/model - what you create is an instance of the class. Now it is no longer just a blueprint, but something that exists with specific values. This is where initializers come in.

Initializers: This is a function (method) that prepares an object for use by setting its initial values. Since your classes and structures are just blueprints, you need an initializer method to specify the rules of assigning values to these blueprints in order to create an instance.

Methods: These are just functions that are associated with a type like an enumeration, class, or structure. We refer to them as methods so that we know that there is a relationship between a function and a type in our code.

Hope this helps!

thanks for that!