-
PassthroughSubject VS CurrentValueSubjectSwiftUI/Basic Property Wrappers 2021. 12. 10. 19:29
PassthroughSubject
A subject that broadcasts elements to downstream subscribers.Declaration
final class PassthroughSubject<Output, Failure> whereFailure : Error
Overview
As a concrete implementation of Subject, the PassthroughSubject provides a convenient way to adapt existing imperative code to the Combine model.
Unlike CurrentValueSubject, a PassthroughSubject doesn’t have an initial value or a buffer of the most recently-published element. A PassthroughSubject drops values if there are no subscribers, or its current demand is zero.
CurrentValueSubject
A subject that wraps a single value and publishes a new element whenever the value changes.Declaration
final class CurrentValueSubject<Output, Failure> whereFailure : Error
Overview
Unlike PassthroughSubject, CurrentValueSubjectmaintains a buffer of the most recently published element.
Calling send(_:) on a CurrentValueSubject also updates the current value, making it equivalent to updating the value directly.
PassthroughSubject: events
CurrentValueSubject: state
'SwiftUI > Basic Property Wrappers' 카테고리의 다른 글
SwiftUI ) StateObject, EnvironmentObject, ObservedObject2 (1) 2021.10.06 SwiftUI ) StateObject Apple Documentation 번역 (0) 2021.10.05 SwiftUI) State, ObservedObject, StateObject, and EnvironmentObject (0) 2021.09.13 SwiftUI) State, Binding wrapper (0) 2021.09.13 SwiftUI) Binding, presentationMode (Two ways to dismiss view) (0) 2021.09.13