diff --git a/README.md b/README.md index 5aafee6..73c6b2d 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 statements, 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'.