There are many way to do this one of the best way is using protocol and delegate.

You can create one protocol and extend that protocol in your ViewController1. Now create the delegate of protocol in ViewController2 and pass reference of that delegate in the ViewController1'sprepareForSegue method.

First create one protocol like this

protocol PassdataDelegate {
func passData()
}

Now extend this protocol in ViewController1 like this and pass the reference of delegate in prepareForSegue method