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

Rich Braymiller
Rich Braymiller
7,119 Points

Wondering if someone can properly define .self to me?

.self seems a little confusing and not sure how well it was explained..anyone out there who can help me better understand this?

2 Answers

Daren Davis
Daren Davis
6,929 Points

as in self.property_Variable or (Attribute), think of it this way. You have created your object and when you refer to it within your definition. instead of putting "the name of the object you created in the future". whatever attribute or property_variable, you just use "self".whatever as placeholder.

Jorge Solana
Jorge Solana
6,064 Points

If I didn't get it wrong:

  • Classes and Structs may have different functions/methods coded inside.
  • Each of these can have its own variables that can be named the same as the Class Attributes/Properties.
  • In case you need to refer to any of the Class properties you can use the self so code can understand when you are referring to the class prop and when to the func/method variable