the data passing between controllers using combine is not working

Your code is almost right, except you are using your Anycancellable inside viewdidload, so its scope is getting exhausted. So use it outside in the view controller as an optional AnyCancellable type. Below code should work.

class vc1: ViewController {
var subscription = AnyCancellable?

   func viewdidLoad() {
     self.subscription = Parent.shared.oublisehr.sink { (result) in
         print(result)
     }
   }
  func navigatetoVC1() {
  ///// some code to navigate to vc1
  }

  func button() {
    self.navigatetoVC1
  }

}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top