In Xcode 10.3, Listing 25.4 compiles and runs. In other words, the Point class is Equatable with no further programming.
Yes and this is wonderful! As of Swift 4.1, the compiler will now synthesize a default implementation of the ==
operator (for structs only!), which will check all of the struct’s fields. This means that most of the time, we no longer need to implement it ourselves in order to be Equatable
-conformant!
That said, if we need a definition of equability that differs from a naive check of all of our properties, or if we have non-Equatable properties, then we’ll need to implement it ourselves. One example: if you have a Book
type, you don’t need to check its ISBN, title, author, and full text content in order to decide that two books are equal. It may be sufficient (and much faster) to say that two books are equal if they have the same ISBN.
Agreed that it is wonderful! I just posted a note to (a) help with the updated edition and (b) let others know about this discrepancy. Thank for your note.