Q:

Passing data to another ViewController without moving to the ViewController

I have a sign up flow with different view controllers. I take input from user in ViewController1, move to the next view controller (ViewController2), and pass the data to the last view controller (for e.g ViewController5).
The issue is I can pass my data to the next view controller but I can’t pass it to the last view controller, as in:
// Move to Second View of the flow.
let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: “SecondViewController“) as! SecondViewController
secondViewController.dataText = dataText!
self.navigationController?.show(secondViewController, sender: nil)

// Pass the data to the last View of the flow.
let fifthViewController = self.storyboard?.instantiateViewController(withIdentifier: “FifthViewController“) as! FifthViewController
fifthViewController.dataText = emailText!

The dataText would pass to the SecondViewController but not the FifthViewController. How do I achieve this?

A:

you can use class and create singleton object to store data and retrieve
in fifth view controller 
class SingletonClass {
    var sharedInstance: SingletonClass {
          struct Static {
               static let instance = SingletonClass()
          }
          return Static.instance
     }
     var dataText : String = ""
}

now you can store data in singleton object like this as below
 let singleTon = SingletonClass()
 singleTon.sharedInstance.dataText = "store data"

and use like this in your fifthViewController
  let singleTon = SingletonClass()
  print(singleTon.sharedInstance.dataText)

