Well, geez. That definitely cleans up the code! And now that I’m looking at it, should have been an obvious solution.
BUT, my original post shows verbatim what was in the book. I can see logically why the code in the book would consider those coordinates to be type (x,y) and not Location — BUT … for the sake of understanding … why/how is the code in my original post shown in the book as instruction? In other words, why can’t I match what is in the book?
Post the definition of the distance() function in the book, and repost exactly what code you are referring to that is in the book so that I know what you are talking about.
To call that, you have to spell out each int separately, as two tuples of two ints each. The earlier code calls it this way.
Further down (six pages or so), there is a mini-exercise described thus:
• Change distance(from:to:) to use Locations as parameters instead of x-y tuples.
Once you do that (I think you did!), you now have to pass in Locations, and can’t just pass tuples.
So when you get to the point where this call works:
let distanceToStore =
distance(from: Location(x: area.center.x, y: area.center.y),
to: Location(x: location.x, y: location.y))
you are passing in locations, and can just simplify it to:
let distanceToStore = distance(from: area.center, to: location)