Error transferring value from one view controller to another on dismiss.
I have a value in ViewController2
that I would like to transfer to ViewController1
on dismiss. In view ViewController2
I do the following to dismiss:
func OtherFunction() {
passAndDismiss(scannedScript: stringCodeValue)
}
Note: stringCode
value is indeed being passed as a String to scannedScript
func passAndDismiss(scannedScript: String) {
dismiss(animated: true, completion: {
let viewcontroller = ViewController1()
viewcontroller.Textfield1.text = scannedScript
})
}
The error occurs on line:
viewcontroller.Textfield1.text = scannedScript
The error I get is:
Unexpectedly found nil while implicitly unwrapping an Optional value