8000 Merge pull request #1 from github/jspahrsummers-patch-1 · smashcoding/swift-style-guide@334ec03 · GitHub
[go: up one dir, main page]

Skip to content

Commit 334ec03

Browse files
committed
Merge pull request github#1 from github/jspahrsummers-patch-1
Prefer implicit getters on computed properties
2 parents e128d20 + 2e53062 commit 334ec03

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
1-
swift-style-guide
2-=================
1+
#### Prefer implicit getters on read-only properties and subscripts
32

4-
Style guide & coding conventions for Swift projects
3+
When possible, omit the `get` keyword on read-only computed properties and
4+
read-only subscripts.
5+
6+
So, write these:
7+
8+
```swift
9+
var myGreatProperty: Int {
10+
return 4
11+
}
12+
13+
subscript(index: Int) -> T {
14+
return objects[index]
15+
}
16+
```
17+
18+
… not these:
19+
20+
```swift
21+
var myGreatProperty: Int {
22+
get {
23+
return 4
24+
}
25+
}
26+
27+
subscript(index: Int) -> T {
28+
get {
29+
return objects[index]
30+
}
31+
}
32+
```
33+
34+
_Rationale:_ The intent and meaning of the first version is clear, and results in less code.

0 commit comments

Comments
 (0)
0