Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
`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