Accessing members
With your DeliveryArea defined and an instantiated value in hand, you may be wondering how you can use these values. Just as you have been doing with Strings, Arrays, and Dictionaries, use the dot syntax to access members:
print(storeArea.range) // 4.0
You can even access members of members using dot syntax:
print(storeArea.center.x) // 2.0
Similar to how you can read values with dot syntax, you can also assign them. If the delivery range of one pizza location becomes larger, you could assign the new value to the existing property:
storeArea.range = 250
The semantics of constants and variables play a significant role in determining if a property can be assigned to. In this case, you can assign to range because you declared it with var. On the other hand, you declared center with let, so you can’t modify it. Your DeliveryArea struct allows a pizza restaurant’s delivery range to be changed, but not its location!
In addition to properties, you must declare the struct itself as a variable to be able to modify it after it is initialized:
let fixedArea = DeliveryArea(range: 4, center: storeLocation)
// Error: change let to var above to make it mutable. fixedArea.range = 250