Skip to content

Instantly share code, notes, and snippets.

@yusuke024
Created June 13, 2019 09:52
Show Gist options
  • Save yusuke024/15d41c6d068ee5304644ee5fdd49f4c3 to your computer and use it in GitHub Desktop.
Save yusuke024/15d41c6d068ee5304644ee5fdd49f4c3 to your computer and use it in GitHub Desktop.
```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