Created
June 13, 2019 09:52
-
-
Save yusuke024/15d41c6d068ee5304644ee5fdd49f4c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```swift | |
⭕️ | |
observable1.flatMap { [weak self] ... in | |
print(self?.value) | |
return observable2.flatMap { ... in in | |
print(self?.value) | |
} | |
} | |
⭕️ | |
observable1.flatMap { [weak self] ... in | |
guard let self = self else { return .empty() } | |
print(self.value) | |
return observable2.flatMap { [weak self] ... in in | |
print(self?.value) | |
} | |
} | |
⭕️ | |
observable1.flatMap { [weak self] ... in | |
print(self?.value) | |
return observable2.flatMap { ... in in | |
guard let self = self else { return .empty() } | |
print(self.value) | |
} | |
} | |
⭕️ | |
observable1.flatMap { [weak self] ... in | |
guard let self = self else { return .empty() } | |
print(self.value) | |
return observable2.flatMap { [weak self] ... in in | |
guard let self = self else { return .empty() } | |
print(self.value) | |
} | |
} | |
⭕️ // But might cause crash 💥 | |
observable1.flatMap { [unowned self] ... in | |
print(self.value) | |
return observable2.flatMap { ... in in | |
print(self.value) | |
} | |
} | |
❌ // No guarantee that there won't be any retain-cycles. It depends on other factors. | |
observable1.flatMap { ... in | |
print(self.value) | |
return observable2.flatMap { ... in in | |
print(self.value) | |
} | |
} | |
❌ // No guarantee that there won't be any retain-cycles. It depends on other factors. | |
observable1.flatMap { [weak self] ... in | |
guard let self = self else { return .empty() } | |
print(self.value) | |
return observable2.flatMap { ... in in | |
print(self.value) | |
} | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment