Swift Language Structs Accessing members of struct

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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


Got any Swift Language Question?