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 ?
here is my code shown below
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
and I tried to pass model class data to another using user defaults but it was not successful and I used below data
here is my code
if let jsonData = try? JSONEncoder().encode(self.guestShippingAddressModel) {
print("To Save:", jsonData)
//Save as data
UserDefaults.standard.set(jsonData,forKey: "guestAddress")
}
to decode model class data I was using below code
if let data = UserDefaults.standard.data(forKey: "guestAddress"),
let sorts = try? JSONDecoder().decode(GuestAddress.self, from: data) {
print("Retrieved:", sorts)
self.guestShippingAddressModel = sorts
}