Merge pull request #48 from poisonedslo/master · github/swift-style-guide@1e23889 · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 1e23889

Browse files
committed
Merge pull request #48 from poisonedslo/master
Added a section about guard statement
2 parents 899a75e + a17ebda commit 1e23889

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,29 @@ It becomes easier to reason about code. Had you used `var` while still making th
3434

3535
Accordingly, whenever you see a `var` identifier being used, assume that it will change and ask yourself why.
3636

37+
### Return and break early
38+
39+
When you have to meet certain criteria to continue execution, try to exit early. So, instead of this:
40+
41+
```swift
42+
if n.isNumber {
43+
// Use n here
44+
} else {
45+
return
46+
}
47+
```
48+
49+
use this:
50+
```swift
51+
guard n.isNumber else {
52+
return
53+
}
54+
// Use n here
55+
```
56+
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+
59+
3760
#### Avoid Using Force-Unwrapping of Optionals
3861

3962
If you have an identifier `foo` of type `FooType?` or `FooType!`, don't force-unwrap it to get to the underlying value (`foo!`) if possible.

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

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.