You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 9, 2017. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+36-36Lines changed: 36 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -34,27 +34,27 @@ It becomes easier to reason about code. Had you used `var` while still making th
34
34
35
35
Accordingly, whenever you see a `var` identifier being used, assume that it will change and ask yourself why.
36
36
37
-
#### Use `guard` statements to exit early
37
+
###Return and break early
38
38
39
-
If you have to meet certain criteria to continue execution, prefer `guard` over `if`
39
+
When you have to meet certain criteria to continue execution, try to exit early. So, instead of this:
40
40
41
-
So, use this:
42
41
```swift
43
-
guardlet foo = foo else {
42
+
if n.isNumber {
43
+
// Use n here
44
+
} else {
44
45
return
45
46
}
46
-
// Use unwrapped `foo` value in here
47
47
```
48
-
Instead of this:
48
+
49
+
use this:
49
50
```swift
50
-
iflet foo = foo {
51
-
// Use unwrapped `foo` value in here
52
-
} else {
51
+
guard n.isNumber else {
53
52
return
54
53
}
54
+
// Use n here
55
55
```
56
56
57
-
_Rationale:_ Intention and criteria are clearly visible, leading to lower chance of programmer error
57
+
You can also do it with `if` statement, but using `guard` is prefered, because `guard` statement without `return`, `break` or `continue` produces a compile-time error, so exit is guaranteed.
58
58
59
59
#### Avoid Using Force-Unwrapping of Optionals
60
60
@@ -94,7 +94,7 @@ So, write these:
94
94
95
95
```swift
96
96
var myGreatProperty: Int {
97
-
return4
97
+
return4
98
98
}
99
99
100
100
subscript(index: Int) -> T {
@@ -106,9 +106,9 @@ subscript(index: Int) -> T {
106
106
107
107
```swift
108
108
var myGreatProperty: Int {
109
-
get {
110
-
return4
111
-
}
109
+
get {
110
+
return4
111
+
}
112
112
}
113
113
114
114
subscript(index: Int) -> T {
@@ -134,7 +134,7 @@ However, definitions within those can leave access control implicit, where appro
134
134
135
135
```swift
136
136
internalstructTheFez {
137
-
var owner: Person =Joshaber()
137
+
var owner: Person =Joshaber()
138
138
}
139
139
```
140
140
@@ -169,27 +169,27 @@ When accessing properties or methods on `self`, leave the reference to `self` im
169
169
170
170
```swift
171
171
privateclassHistory {
172
-
var events: [Event]
172
+
var events: [Event]
173
173
174
-
funcrewrite() {
175
-
events = []
176
-
}
174
+
funcrewrite() {
175
+
events = []
176
+
}
177
177
}
178
178
```
179
179
180
180
Only include the explicit keyword when required by the language—for example, in a closure, or when parameter names conflict:
181
181
182
182
```swift
183
183
extensionHistory {
184
-
init(events: [Event]) {
185
-
self.events= events
186
-
}
187
-
188
-
var whenVictorious: () -> () {
189
-
return {
190
-
self.rewrite()
191
-
}
192
-
}
184
+
init(events: [Event]) {
185
+
self.events= events
186
+
}
187
+
188
+
var whenVictorious: () -> () {
189
+
return {
190
+
self.rewrite()
191
+
}
192
+
}
193
193
}
194
194
```
195
195
@@ -264,21 +264,21 @@ Methods of parameterized types can omit type parameters on the receiving type wh
Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.
Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.
🎥 Watch TMZ Live
TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.
0 commit comments