Member-only story

Default a View in NavigationView with SwiftUI

Jay Wilson
5 min readNov 8, 2019

I’m going to walk through the steps to create a default view in a NavigationViewin 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!")
}

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Jay Wilson
Jay Wilson

Written by Jay Wilson

I like to solve problems using Swift, make YouTube videos, and take photos. I also really enjoy a good cup of coffee.

No responses yet

Write a response