From 5cc05f59bd14505e491e1b0fb2cc56e0c03ba788 Mon Sep 17 00:00:00 2001 From: vinagrito Date: Tue, 7 Feb 2017 12:26:21 +0200 Subject: [PATCH 1/2] Adds styling for if-else conditional --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 5aafee6..59d51ef 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Here are some of the documents from Apple that informed the style guide. If some * [Booleans](#booleans) * [Conditionals](#conditionals) * [Ternary Operator](#ternary-operator) + * [If-Else Operator] * [Init Methods](#init-methods) * [Class Constructor Methods](#class-constructor-methods) * [CGRect Functions](#cgrect-functions) @@ -561,6 +562,32 @@ result = isHorizontal ? x : y; result = a > b ? x = c > d ? c : d : y; ``` +### If-Else + +The if-else conditional should be used when having to perform different sets of actions depending on an evaluation. During the evaluation seems clearer to implement positive questions, i.e without the use of the `not` (`!`) operator. + +**Preferred:** + +```objc +if (error) { + // Do something +} else { + // Do something else +} + +``` + +**Not Preferred:** + +```objc +if (!error) { + // Do something +} else { + // Do something else +} + +``` + ## Init Methods Init methods should follow the convention provided by Apple's generated code template. A return type of 'instancetype' should also be used instead of 'id'. From 61d842232d293f619cc7b50940e6f36d6c58e60e Mon Sep 17 00:00:00 2001 From: "Daniel E. Garcia Shulman" Date: Tue, 7 Feb 2017 18:49:46 +0200 Subject: [PATCH 2/2] more precise wording --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 59d51ef..73c6b2d 100644 --- a/README.md +++ b/README.md @@ -564,7 +564,7 @@ result = a > b ? x = c > d ? c : d : y; ### If-Else -The if-else conditional should be used when having to perform different sets of actions depending on an evaluation. During the evaluation seems clearer to implement positive questions, i.e without the use of the `not` (`!`) operator. +The if-else conditional should be used when having to perform different sets of actions depending on an evaluation. During the evaluation seems clearer to implement positive statements, i.e without the use of the `not` (`!`) operator. **Preferred:**