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 trialRosario Rascuna
363 Pointsgetter method and self
How come in the 'predictions' getter method, we use _prediction instead of using self._predictions?
1 Answer
Stone Preston
42,016 Points_predictions is the variable your property created behind the scenes. We can access that variable just fine by using _predictions
. Using self._predictions
really translates into [self _predictions]
and your class doesnt have a method called _predictions, it only has the variable _predictions
I know its confusing, just remember that in getter/setter methods you access the variable directly using _variableName, not self.variableName or self._variableName;
you access properties of your class using self.propertyName
because this translates into [self propertyName]
which calls the getter method of your property. the getter method name is simply propertyName