Component - Passing data to destination
This UI component shows how to send data from one screen to another in an iOS app using Swift. When you tap a button, it moves to a new screen and shows the passed message.
This UI component shows how to send data from one screen to another in an iOS app using Swift. When you tap a button, it moves to a new screen and shows the passed message.
NavigationView
└── VStack
├── Text ("First Screen")
└── NavigationLink
└── Text ("Go to Second Screen")
SecondView (receives message)destinationVC.userName after the segue?override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetail" {
let destinationVC = segue.destination as! DetailViewController
destinationVC.userName = "Alice"
}
}override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destinationVC = segue.destination as! DetailViewController
destinationVC.data = "Hello"
}GameViewController to ResultViewController using a segue with identifier "showResult". Which code snippet correctly passes the score safely?Pass the test and this pattern moves unknown