Customize handling of asynchronous events by combining event-processing operators using Combine.

Combine Documentation

Posts under Combine tag

23 Posts
Sort by:
Post not yet marked as solved
0 Replies
681 Views
Can someone please help me understand PassthroughSubject and CurrentValueSubject? What I understand so far is that they are subjects where subscribers can listen to changes made to these subjects, but I'm really straggling to understand the following. I'm I correct by saying that PassthroughSubject or CurrentValueSubject could replace delegation and asynchronous function calls? Is it possible to delare a subject in Class A and subscribe to listen to those subject changes in Class B and in some other classes or are listeners meant to only be used direclty in SwiftUI structs? Thanks
Posted
by fsdolphin.
Last updated
.
Post not yet marked as solved
1 Replies
1.2k Views
I'm trying to get push tokens for Live Activities but I am getting the same token twice, Why is that? Is there any other way to get the token just once, so I can hit the API to save the token. Here's the code: Task { for await data in runningActivity.pushTokenUpdates { let myToken = data.hexString self.count += 1 print("Count \(self.count)\n" + myToken) } Output: Count 1 80dc21086f81.........646d7084805dc Count 2 80dc21086f81.........646d7084805dc I can't seem to understand why this is happening, and some times it takes significantly longer to get the tokens. Am I doing anything wrong? Please do share your thoughts. Thank you!
Posted Last updated
.
Post not yet marked as solved
0 Replies
536 Views
What is the expected thread on which a .collect operation in Swift's Combine will emit? Specifically I am seeing this code crash in the second precondition, but not the first: return Publishers.MergeMany(publishers) .handleEvents(receiveOutput: { _ in precondition(Thread.isMainThread) // <- This is fine }) .collect() .handleEvents(receiveOutput: { _ in precondition(Thread.isMainThread) // <- Crash is here }) It is as if the .collect operation is picking a different thread to use, even though the final publisher in the MergeMany must have emitted on the main thread. I have deduced this behavior via crash logs uploaded from Firebase. Can anyone explain this observed behavior?
Posted
by es1997.
Last updated
.