March 2017
Intermediate to advanced
226 pages
5h 13m
English
Swift allows you to move beyond simple properties to implement custom getters and setters as well as property observers that allow you to react to value changes. Here are some thoughts about preferred practices to use when implementing these features.
When working with read-only computed properties, prefer to remove the get keyword and surrounding braces. The first of the following examples is more concise and just as effective as the second:
| | var area: Double { // yes |
| | return width * height |
| | } |
| | |
| | var area: Double { // no |
| | get { return width * height } |
| | } |
Swift setters and property observers supply predefined implicit value argument symbols. ...
Read now
Unlock full access