Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

36
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda