Skip to content

Adds styling for if-else conditional #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'.
Expand Down