Skip to content

Commit 1bd044a

Browse files
authored
minor swift 3 typo fixes
1 parent 1a99e39 commit 1bd044a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,12 @@ func handleProblem(problem: Problem) {
568568

569569
```swift
570570
func handleDigit(_ digit: Int) throws {
571+
switch digit {
571572
case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9:
572573
print("Yes, \(digit) is a digit!")
573574
default:
574575
throw Error(message: "The given number was not a digit.")
576+
}
575577
}
576578
```
577579

@@ -608,7 +610,7 @@ unowned var parentViewController: UIViewController
608610

609611
* **3.5.5** When unwrapping optionals, use the same name for the unwrapped constant or variable where appropriate.
610612

611-
```
613+
```swift
612614
guard let myValue = myValue else {
613615
return
614616
}
@@ -727,9 +729,9 @@ doSomething(1.0, success: { (parameter1) in
727729

728730
### 3.9 Arrays
729731

730-
* **3.9.1** In general, avoid accessing an array directly with subscripts. When possible, use accessors such as `.first` or `.last`, which are optional and won’t crash. Prefer using a `for item in items` syntax when possible as opposed to something like `for i in 0..<items.count`. If you need to access an array subscript directly, make sure to do proper bounds checking. You can use `for (index, value) in items.enumerate()` to get both the index and the value.
732+
* **3.9.1** In general, avoid accessing an array directly with subscripts. When possible, use accessors such as `.first` or `.last`, which are optional and won’t crash. Prefer using a `for item in items` syntax when possible as opposed to something like `for i in 0 ..< items.count`. If you need to access an array subscript directly, make sure to do proper bounds checking. You can use `for (index, value) in items.enumerated()` to get both the index and the value.
731733

732-
* **3.9.2** Never use the `+=` or `+` operator to append/concatenate to arrays. Instead, use `.append()` or `.appendContentsOf()` as these are far more performant (at least with respect to compilation) in Swift's current state. If you are declaring an array that is based on other arrays and want to keep it immutable, instead of `let myNewArray = arr1 + arr2`, use `let myNewArray = [arr1, arr2].flatten()`.
734+
* **3.9.2** Never use the `+=` or `+` operator to append/concatenate to arrays. Instead, use `.append()` or `.append(contentsOf:)` as these are far more performant (at least with respect to compilation) in Swift's current state. If you are declaring an array that is based on other arrays and want to keep it immutable, instead of `let myNewArray = arr1 + arr2`, use `let myNewArray = [arr1, arr2].flatten()`.
733735

734736
### 3.10 Error Handling
735737

@@ -899,7 +901,7 @@ if let monkeyIsland = monkeyIsland {
899901
bookVacation(onIsland: monkeyIsland)
900902
}
901903

902-
if let woodchuck = woodchuck where canChuckWood(woodchuck) {
904+
if let woodchuck = woodchuck, canChuckWood(woodchuck) {
903905
woodchuck.chuckWood()
904906
}
905907
```

0 commit comments

Comments
 (0)