What if you could send information between screens without writing messy code every time?
Why Passing data to destination in iOS Swift? - Purpose & Use Cases
Imagine you have two screens in your app: one shows a list of friends, and the other shows details about a selected friend. You want to send the friend's name and photo from the list screen to the detail screen manually.
Doing this manually means writing lots of code to find the right screen, create it, and then copy each piece of data one by one. It's easy to forget something or make mistakes, and the code becomes messy and hard to fix.
Passing data to destination lets you send all the needed information smoothly when moving from one screen to another. It keeps your code clean and makes sure the right data arrives exactly where it should.
let detailVC = DetailViewController() detailVC.name = selectedName detailVC.photo = selectedPhoto navigationController?.pushViewController(detailVC, animated: true)
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let detailVC = segue.destination as? DetailViewController { detailVC.name = selectedName detailVC.photo = selectedPhoto } }
This makes your app flow naturally, letting users see the right information instantly when they move between screens.
When you tap a contact in your phone's address book, the app passes that contact's details to the next screen so you can see their phone number and email without delay.
Passing data to destination avoids messy manual copying.
It keeps your app's navigation smooth and reliable.
It helps users get the right info exactly when they need it.