Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active April 9, 2020 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdev/d246ade5c20c6ad6a531fb3dbe42277e to your computer and use it in GitHub Desktop.
Save jasdev/d246ade5c20c6ad6a531fb3dbe42277e to your computer and use it in GitHub Desktop.
`RandomNumberViewModel` `replaceError` attempt.
final class RandomNumberViewModel: ObservableObject {
/* … */
init() {
randomNumberPing
.map {
randomNumberPublisher()
.map(Optional.some) /// (1) Boxing values into an `Optional`.
.replaceError(with: nil) /// (2) Swapping out errors with `nil`s.
}
.switchToLatest()
.print()
.receive(on: DispatchQueue.main)
.assign(to: \.randomNumber, onWeak: self)
.store(in: &subscriptions)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment