Passing Data to Detail Views
Send the selected item to the next screen.
Detail Screens Need Data
A detail screen is only useful if it knows which item to show. So when you push it, you hand the selected piece of data straight into the new view. 📦
Pass Through the Initializer
The cleanest way to send data is the detail view initializer. Store the value in a property, then read it inside the body.
struct DetailView: View {
let title: String
var body: some View { Text(title) }
}All lessons in this course
- Pushing Screens with NavigationLink
- Passing Data to Detail Views
- Toolbar & Navigation Title
- Programmatic Navigation Paths