Search code examples
swiftpropertiesgetter-setter

swift properties empty setters and getters


I'm a beginner in Ios development so please forgive me if this sounds like a silly question. I often see properties declaration like this:

var desiredAccuracy: CLLocationAccuracy { get set }

so what does { get set } mean? Is it an empty getter and setter for a variable?


Solution

  • This is how a property requirement is declared in a protocol:

    Property requirements are always declared as variable properties, prefixed with the var keyword. Gettable and settable properties are indicated by writing { get set } after their type declaration, and gettable properties are indicated by writing { get }.

    Apple Swift documentation