Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

35
Views
Why is PassthroughSubject not published?

I want a "controller" or "viewmodel" object to be informed of changes to an object in the data model. So I set up a Combine editor on the data model object, which publishes every time one of its member values changes:

 import Foundation
import Combine

class User : Codable, Equatable, ObservableObject
{
 var ID: String = ""
 {
 didSet {
 changePublisher.send(self)
 }
 }
 var pw: String = ""
 {
 didSet {
 changePublisher.send(self)
 }
 }
 var username: String = ""
 {
 didSet {
 changePublisher.send(self)
 }
 }
 var firstName: String = ""
 {
 didSet {
 changePublisher.send(self)
 }
 }
 var lastName: String = ""
 {
 didSet {
 changePublisher.send(self)
 }
 }
 var validated: Bool = false
 {
 didSet {
 print("Publishing validated change.")
 changePublisher.send(self)
 }
 }

 let changePublisher = PassthroughSubject<User, Never>()
...
}

And here is the object that wants to know about the changes made to the previous User:

 class UserManager : ObservableObject
{
 var model: CentralModel

 var userChangePipeline: [AnyCancellable] = []

 init(withModel: CentralModel)
 {
 model = withModel
 model.user.changePublisher.sink(receiveValue: { changedUser in
 print("Changed-user validation: \(changedUser.validated)")
 .store(in: &userChangePipeline)
 }
 ...
}

The User object prints the message "publishing change validated" when I modify that value, showing that the didSet methods are called. But the subscriber's receiver is never called. Please note that I am saving the subscription.

over 2 years ago · Carlos Garzón Colorado
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!