Accessing members of struct

suggest change

In Swift, structures use a simple “dot syntax” to access their members.

For example:

struct DeliveryRange {
  var range: Double
  let center: Location
}
let storeLocation = Location(latitude: 44.9871,
                             longitude: -93.2758)
var pizzaRange = DeliveryRange(range: 200,
                               center: storeLocation)

You can access(print) the range like this:

print(pizzaRange.range) // 200

You can even access members of members using dot syntax:

print(pizzaRange.center.latitude) // 44.9871

Similar to how you can read values with dot syntax, you can also assign them.

pizzaRange.range = 250

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents