Member-only story
Default a View in NavigationView with SwiftUI
I’m going to walk through the steps to create a default view in a NavigationView
in a brand new project.

The finished project can be found on my GitHub by clicking here.
1. Create a Single View App
Create a new XCode project using SwiftUI.
2. In ContentView.swift
, add a NavigationView
A fresh ContentView.swift
looks like this:
import SwiftUIstruct ContentView: View {
var body: some View {
Text("Hello, World!")
}
}struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
To add a NavigationView that looks like a list, we first need to embed the Text
in a List
. Embedding in a List
can be done by CMD + Click
on Text
and choosing Embed in List from the menu.
You should then get the code sample below.
struct ContentView: View {
var body: some View {
List(0 ..< 5) { item in
Text("Hello, World!")
}…