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
Richard Purba
iOS Development Techdegree Student 2,764 PointsWhy not self.strength?
In this video, the override method is using the decreaseHealth method, as the following
enemy.decreaseHealth(strength)
Why not self.strength, given the fact that we are calling the self property of the subclass?
1 Answer
Michael Hulet
47,913 PointsIn most cases in Swift, the use of self is implied, and you don't always need to type self. before you access symbols from other methods on the same object. The only exception to this is inside of closures, in which self is captured incase the closure's lifetime is longer than self. That may sound complicated, but all you really need to know from that is that you don't have to write self, except inside of closures
kyrmyzykaliyeva
1,612 Pointskyrmyzykaliyeva
1,612 PointsThe class sends its own strength parameter: 50 or 100. We use self when we want to call or work with instance. Here is we are not working with instance. We r just overriding method.