Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

42
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda