Skip to content

Commit

Permalink
Correct the idiom for extending lifetime.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcritz committed Aug 3, 2018
1 parent 4d4a01e commit a20abff
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -682,16 +682,16 @@ Code (even non-production, tutorial demo code) should not create reference cycle

### Extending object lifetime

Extend object lifetime using the `[weak self]` and `guard let strongSelf = self else { return }` idiom. `[weak self]` is preferred to `[unowned self]` where it is not immediately obvious that `self` outlives the closure. Explicitly extending lifetime is preferred to optional unwrapping.
Extend object lifetime using the `[weak self]` and ```guard let `self` = self else { return }``` idiom. `[weak self]` is preferred to `[unowned self]` where it is not immediately obvious that `self` outlives the closure. Explicitly extending lifetime is preferred to optional unwrapping. In Swift 4.2, you should drop the backticks in the guard statement.

**Preferred**
```swift
resource.request().onComplete { [weak self] response in
guard let strongSelf = self else {
guard let `self` = self else {
return
}
let model = strongSelf.updateModel(response)
strongSelf.updateUI(model)
let model = self.updateModel(response)
self.updateUI(model)
}
```

Expand Down

0 comments on commit a20abff

Please sign in to comment.