Skip to content

Commit

Permalink
Merge pull request #30 from Trendyol/loops
Browse files Browse the repository at this point in the history
Update code_style_guideline.md loops
  • Loading branch information
eyupgoymen committed May 17, 2024
2 parents 2be46ff + a4a679c commit 3744d0e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions code_style_guideline/code_style_guideline.md
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,51 @@ struct Stack<T> { ... }
func write<target: OutputStream>(to target: inout target)
func swap<Thing>(_ a: inout Thing, _ b: inout Thing)
```
### Loops
### 1. Where Clause
Prefer to use where clause if it's possible.

**Preferred**:
```swift
for item in items where item.productCount > 1 {
...
}
```

**Not Preferred**:
```swift
for item in items {
if item.productCount > 1 {

}
}
```

### 2. Indices
Use .indicies property to loop over array indexes.

**Preferred**:
```swift
for index in array.indices {

}
```

**Not Preferred**:
```swift
for index in 0..<array.count {

}
```

### 3. Enumarated
Use .enumarated to loop through both index and item.

```swift
for (index, item) in array.enumarated() {

}
```

### Class and Structs
### 1. Controller Suffix
Expand Down

0 comments on commit 3744d0e

Please sign in to comment.