I am creating a function that allows me to create a array on VC1 and then I can transfer over the array using "prepare for segue" to VC2. On VC2 I can append an item to the array in VC2 and then transfer over the array back to VC1. My issue is, is that on the line
if let newString = receivedString
var receivedString = [String]()
override func viewDidAppear(_ animated: Bool) {
if let newString = receivedString {
print(newString)
}
}
let stringToPass = "Hello World"
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destinationVC = segue.destination as! ViewController
destinationVC.receivedString = [stringToPass]
destinationVC.receivedString.append("DYLAN MURPHY")
}
I would personally do what you want to do a little bit differently. In VC1 I would add this code:
var username = [String]()
In VC2:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "toSecondViewController" {
let hello = segue.destination as! ViewController
hello.username.append(textField.text!)
}
}