0PricingLogin
SwiftUI Academy · Lesson

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

  1. Pushing Screens with NavigationLink
  2. Passing Data to Detail Views
  3. Toolbar & Navigation Title
  4. Programmatic Navigation Paths
← Back to SwiftUI Academy