From e1d5d6318d1c90f8cad4d90ad62a2377194233ec Mon Sep 17 00:00:00 2001 From: Sam Warfield Date: Mon, 28 Jan 2019 09:30:01 -0800 Subject: [PATCH 1/2] Change `guard let strongSelf` to `guard let self` --- README.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index aaf1f62..3a3cf89 100644 --- a/README.md +++ b/README.md @@ -403,13 +403,20 @@ let lastName = name.lastName * **3.1.6** Be careful when calling `self` directly from an escaping closure as this can cause a retain cycle - use a [capture list](https://developer.apple.com/library/ios/documentation/swift/conceptual/Swift_Programming_Language/Closures.html#//apple_ref/doc/uid/TP40014097-CH11-XID_163) when this might be the case: ```swift -myFunctionWithEscapingClosure() { [weak self] (error) -> Void in - // you can do this +myFunctionWithEscapingClosure() { [weak self] in + // PREFERRED + guard let self = self else { + debugPrint("What happened? You lost self...") + return + } + self.doSomething() + + // you can do this + self?.doSomething() - // or you can do this - + // NOT PREFERRED guard let strongSelf = self else { return } From d5c68f3312a9efcf9f7aee3b69fdf29bb3434da8 Mon Sep 17 00:00:00 2001 From: Sam Warfield Date: Mon, 28 Jan 2019 09:37:51 -0800 Subject: [PATCH 2/2] Update README.md --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 3a3cf89..ba2e7ab 100644 --- a/README.md +++ b/README.md @@ -412,10 +412,6 @@ myFunctionWithEscapingClosure() { [weak self] in self.doSomething() - // you can do this - - self?.doSomething() - // NOT PREFERRED guard let strongSelf = self else { return