From 11146a538c48574354e9f1f7247024cae1c6ec37 Mon Sep 17 00:00:00 2001 From: Wojciech Nagrodzki <278594+wnagrodzki@users.noreply.github.com> Date: Sat, 4 Aug 2018 19:55:13 +0200 Subject: [PATCH] Added "Avoid force unwrapping" section --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 80e7c56..ca90cf4 100644 --- a/README.md +++ b/README.md @@ -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.