Code of ViewController (code of file from where you want to pass value):
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var txt1: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func ClickToPass(_ sender: Any) {
let mmi = self.storyboard?.instantiateViewController(withIdentifier: "Second") as! SecondViewController
mmi.passedvalue = txt1.text!
self.navigationController?.pushViewController(mmi, animated: true)
}
}
Code of SecondViewController (code of file where you want to get value):
import UIKit
class SecondViewController: UIViewController {
@IBOutlet weak var label1: UILabel!
var passedvalue = String()
override func viewDidLoad() {
super.viewDidLoad()
label1.text = "Passed value= " + passedvalue
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Screenshots: