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 trialGuillermo Tame
18,583 PointsWhy didn't he just enemy.position == point?
Why didn't he just enemy.position == point? As such if point == enemy.position{....
2 Answers
Steven Parker
231,275 PointsA value equality test ("==") does not by default compare the properties of complex objects. And reference equality ("===") only checks if both references are for the same object.
So for the purpose of this method, it's necessary to compare the properties individually.
It would probably be overkill for this situation, but a type can declare to other code that it supports value equality by conforming to the Equatable
protocol. For details, see the swift reference guide page on Equatable.
Guillermo Tame
18,583 PointsOh, so its like java? I would need to create a "equals" method that overrides the default?
Steven Parker
231,275 PointsYou might only need to declare "Equatable conformance". See the amendment to my answer: