Trying to learn the Combine framework and this operator is popping up: \.
Subscribers.Assign(object: lastPostLabel, keyPath: \.text)
I don't know what to call it to search for it. Anyone have a reference?
Trying to learn the Combine framework and this operator is popping up: \.
Subscribers.Assign(object: lastPostLabel, keyPath: \.text)
I don't know what to call it to search for it. Anyone have a reference?
With with subscriber you can assign an output value of publisher to some object property using key path, like in below example
class ViewModel: ObservableObject {
@Published var text: String = "loading" // property
private var task: AnyCancellable?
func fetch() {
task = Just("done") // ... like long operation here
.delay(for: 1, scheduler: RunLoop.main)
.assign(to: \.text, on: self) // equivalent to self.text = "done"
}
}