Added "Avoid force unwrapping" section

This commit is contained in:
Wojciech Nagrodzki 2018-08-04 19:55:13 +02:00
parent c6d114bf5b
commit 11146a538c
Signed by: wnagrodzki
GPG key ID: E9D0EB0302264569

View file

@ -16,3 +16,13 @@ Declare class `final` unless you explicitly design it to be inheritable. For non
When designing a module prefer `public` for non final class unless you explicitly design it to be inheritable by external clients. For `open` class prefer `public` for members except for those you explicitly design for overriding by external clients.
> Every point that can be overridden increases complexity, thus it should always be a conscious choice to add it.
### Avoid force unwrapping
Use `guard` and `fatalError()` instead of force unwrapping to clarify your intent.
```swift
guard let value = optionalValue else { fatalError("reason why value must be present") }
```
> This is to avoid situations in which reason for force unwrapping is undocumented.