-
-
Notifications
You must be signed in to change notification settings - Fork 416
Observing Publishers
Vatsal Manot edited this page May 29, 2020
·
2 revisions
A property wrapper type that subscribes to an observable object and invalidates a view whenever the observable object changes.
Usage:
struct ContentView: View {
@ObservedPublisher<AnyPublisher<Int, Never>> var value: Int
init() {
_value = .init(
publisher: Publishers.Sequence(sequence: [1, 2, 3, 4, 5])
.flatMap({ Just($0).delay(for: .seconds($0), scheduler: RunLoop.main) })
.eraseToAnyPublisher(),
initial: 0
)
}
var body: some View {
Text("\(value)")
.font(.largeTitle)
.foregroundColor(.primary)
}
}
If you see any problems with the content above, please file an issue here.