Introducing structures

Imagine you live in a town called Pizzaville. As you might expect, Pizzaville is known for it’s amazing pizza. Imagine that you own the most popular (and fastest!) pizza delivery restaurant in Pizzaville — “Swift Pizza”.

As you begin to expand, you want to write a program that calculates if a potential customer is within range of a pizza delivery restaurant. The first version of your program might might look something like this:

Simple enough, right?

A successful pizza delivery business may eventually expand to include multiple locations, which adds a minor twist to the deliverable calculator. Replace your existing code with the following:

secondDeliveryDistance < otherRestaurantRange

}

Eventually, the rising number of customers will force the business to expand, and soon it might grow to a total of 10 stores! Then what? Do you keep updating your function to check against all these sets of coordinates and ranges?

You might briefly consider creating an array of x/y coordinate tuples to keep track of your pizza restaurants, but that would be both difficult to read and maintain.

Fortunately, Swift has additional tools to help you simplify the problem.

results matching ""

    No results matching ""