There are multiple questions along these lines on Stack Overflow, but none seem to simply answer my specific question. I would like to be able to create a label on one view controller that can change what it displays based on the value of a label on another view controller. I am using Xcode 8.2.1 and Swift 3.
Edit
FirstViewController
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showSecondViewController" {
if let viewController = segue.destination as? SecondViewController {
if messageLabel != nil {
SecondViewController.billString = self.messageLabel //error on this line
}
}
}
}
SecondViewController
@IBOutlet weak var billLabel: UILabel!
var billString = "test"
override func viewDidLoad() {
super.viewDidLoad()
billLabel.text = billString
}