How to pass data from one view controller to another in container view? : <p>Here I am displaying view controllers in a container view and here I need to pass the multiple data but here nothing had been passed from the view controller to another can anyone help me how to implement this ?</p>

<p>here is my code shown below</p>

<pre><code>let controller:PaymentViewController = self.storyboard!.instantiateViewController(withIdentifier: "paymentPage") as! PaymentViewController
controller.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
controller.carrierCode = self.responseData[0].carrierCode
controller.methodCode = self.responseData[0].methodCode
controller.willMove(toParentViewController: self)
self.view.addSubview(controller.view)
self.addChildViewController(controller)
controller.didMove(toParentViewController: self)
controller.guestShippingAddressModel = self.guestShippingAddressModel
</code></pre>

<p>and I tried to pass model class data to another using user defaults but it was not successful and I used below data</p>

<p>here is my code </p>

<pre><code> if let jsonData = try? JSONEncoder().encode(self.guestShippingAddressModel) {
   print("To Save:", jsonData)

   //Save as data
   UserDefaults.standard.set(jsonData,forKey: "guestAddress")
  }
</code></pre>

<p>to decode model class data I was using below code</p>

<pre><code>if let data = UserDefaults.standard.data(forKey: "guestAddress"),
   let sorts = try? JSONDecoder().decode(GuestAddress.self, from: data) {
    print("Retrieved:", sorts)
    self.guestShippingAddressModel = sorts
 }
</code></pre>
