Post not yet marked as solved
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
Post not yet marked as solved
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!
Post not yet marked as solved
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?