Call struct from different view controller (swift4)

Hi @timswift, I’m afraid I didn’t explain myself as I should have.
Let me try again.

I assume the following:

  1. You use storyboard
  2. In ViewController we enter the the data to the contact variable
  3. We use segue to move to TwoViewController after pressing on a button

My solution is (with swift pseudo code):

  • in ViewController we use the prepareforsegue function to assign the reference
    • I will use option 2 or 3, it least recommend to use option 1 (if you want I can explain)
  • in TwoViewController use the reference
//in ViewController

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "moveToTwoVC", let twoVC = segue.destination as? TwoViewController {
             // option 1
            twoVC.referanceToOtherViewController = self
            
            // option 2
            twoVC.contacts = contacts
            
            // option 3
            twoVC.person = contacts.first
        }
    }
// in TwoViewController

// option 1
weak var referanceToOtherViewController: ViewController?

// option 2 (can be ? or !)
var contacts: [Person]?

// option 3 (can be ? or !)
var person: Person?

override func viewDidLoad() {
    super.viewDidLoad()
    // option 1
    l.text = referanceToOtherViewController.contacts.first.name
   // option 2
   l.text = contacts.first.name
  // option 3
  l.text = person.name
}