Skip to content

Commit 6bd55b2

Browse files
committed
Add guideline for omitting the get clause on read-only variables
1 parent 1f5b874 commit 6bd55b2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.markdown

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Writing Objective-C? Check out our [Objective-C Style Guide](https://github.com/
1515
* [Classes and Structures](#classes-and-structures)
1616
* [Use of Self](#use-of-self)
1717
* [Protocol Conformance](#protocol-conformance)
18+
* [Computed Properties](#computed-properties)
1819
* [Function Declarations](#function-declarations)
1920
* [Closure Expressions](#closure-expressions)
2021
* [Types](#types)
@@ -258,6 +259,25 @@ class MyViewcontroller: UIViewController, UITableViewDataSource, UIScrollViewDel
258259
}
259260
```
260261

262+
### Computed Properties
263+
264+
For conciseness, if a computed property is read-only, omit the get clause. The get clause is required only when a set clause is provided.
265+
266+
**Preferred:**
267+
```swift
268+
var diameter: Double {
269+
return radius * 2
270+
}
271+
```
272+
273+
**Not Preferred:**
274+
```swift
275+
var diameter: Double {
276+
get {
277+
return radius * 2
278+
}
279+
}
280+
```
261281

262282
## Function Declarations
263283

0 commit comments

Comments
 (0)