# SwiftUI Tutorial: Navigation | raywenderlich.com

**URL:** <https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774>\
**Category:** 🎓 Courses & Articles\
**Created:** [November 11, 2019, 2:35pm UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774 "2019-11-11T14:35:33Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [November 11, 2019, 2:35pm UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774/1 "2019-11-11T14:35:33Z")

</div>

In this tutorial, you’ll use SwiftUI to implement the navigation of a master-detail app. You’ll learn how to implement a navigation stack, a navigation bar button, a context menu and a modal sheet.

* * *
This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/5824937-swiftui-tutorial-navigation](https://www.raywenderlich.com/5824937-swiftui-tutorial-navigation)

---

<div class="post-metadata">

**Author:** ![aoi](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/aoi/32/81494_2.png) [@aoi](https://forums.kodeco.com/u/aoi)\
**Post date:** [November 13, 2019, 5:29pm UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774/2 "2019-11-13T17:29:05Z")

</div>

Thanks for a great tutorial. With regards to the SplitView section, is there a way to have the master view always show while on iPad and not have to swipe right to show it? It would be similar to the Settings app on the iPad where the master view always shows on the left and then the detail is on the right. Thanks.

---

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [November 13, 2019, 9:43pm UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774/3 "2019-11-13T21:43:52Z")

</div>

hi Aoi! do you mean in portrait orientation? there’s a [partial solution](https://stackoverflow.com/questions/57211380/collapse-a-doublecolumn-navigationview-detail-in-swiftui-like-with-collapsed-on/57215664#57215664) on Stack Overflow — you add padding to the `NavigationView`, which squeezes both master and detail view onto the screen. Use `.padding(1)` to minimise the screen loss.

---

<div class="post-metadata">

**Author:** ![aoi](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/aoi/32/81494_2.png) [@aoi](https://forums.kodeco.com/u/aoi)\
**Post date:** [November 13, 2019, 10:40pm UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774/4 "2019-11-13T22:40:10Z")

</div>

Thanks. Yes, a partial work around. What I was looking for was the functionality that UISplitView has: preferredDisplayMode.allVisible. The workaround makes portrait mode look like .allVisible but seems to break in landscape mode for me. I guess this is something that Apple hasn’t provided for yet.? Is there a way to add a back button on the detail view so that the user when presented with just the detail view can see that the masterview is off screen and make it appear without swiping?  
Mike

---

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [November 13, 2019, 11:51pm UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774/5 "2019-11-13T23:51:56Z")

</div>

hi Mike! yes, Apple hasn’t yet implemented everything from UIKit, so they provide `UIViewControllerRepresentable` and `UIViewRepresentable` — you can extend `UISplitViewController` to conform to `UIViewControllerRepresentable`, then use it in your SwiftUI app.

The other standard suggestion is to force `StackNavigationViewStyle`, so your iPad app behaves like the iPhone version — back button etc.

---

<div class="post-metadata">

**Author:** ![danieleprice1](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/danieleprice1/32/81494_2.png) [@danieleprice1](https://forums.kodeco.com/u/danieleprice1)\
**Post date:** [December 3, 2019, 7:04pm UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774/6 "2019-12-03T19:04:03Z")

</div>

Thanks for clarifying how SwiftUI applies indices. I’ve followed this and a couple other tutorials, but struggling to apply to a list within a list without creating additional classes, structs, or enums.

In this example, rather than use tabs, how would one “group” based on disciplines? In other words, the master would list the disciplines, each with a navigation link to a list of artwork of that type of discipline and then each of those would have a link to the DetailView.

---

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [December 4, 2019, 9:47pm UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774/7 "2019-12-04T21:47:42Z")

</div>

hi Daniel! you’d just make the first detail view a list with navigation link. Here’s a rough draft. An enum would be useful, and a func or computed property to filter the full array of artworks. Here, I just pass the statues array.

Live preview shows two back buttons on the final artwork view, so you can return to Statues or to Disciplines … looks odd, but useful, I guess 😉

```
    import SwiftUI

    struct ContentView: View {
      let disciplines = ["Statue", "Mural", "Plaque"]
      
      let statues = ["Kuhio", "Kalakaua"]
      let murals = ["Water", "Couple"]
      let plaques = ["Earhart", "Marin"]
      
      var body: some View {
        NavigationView {
          List(disciplines, id: \.self) { discipline in
            NavigationLink(
            destination: DetailView(discipline: discipline, artworks: self.statues)) {
              Text(discipline)
            }
          }
          .navigationBarTitle("Disciplines")
        }
      }
    }

    struct DetailView: View {
      let discipline: String
      let artworks: [String]
      
      var body: some View {
        NavigationView {
          List(artworks, id: \.self) { artwork in
            NavigationLink(
            destination: ArtView(artwork: artwork)) {
              Text(artwork)
            }
          }
          .navigationBarTitle("Statues")
        }
      }
    }

    struct ArtView: View {
      let artwork: String
      var body: some View {
        Text(artwork)
      }
    }

    struct ContentView_Previews: PreviewProvider {
      static var previews: some View {
        ContentView()
      }
    }

```

---

<div class="post-metadata">

**Author:** ![danieleprice1](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/danieleprice1/32/81494_2.png) [@danieleprice1](https://forums.kodeco.com/u/danieleprice1)\
**Post date:** [December 5, 2019, 12:36am UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774/9 "2019-12-05T00:36:16Z")

</div>

Thanks Audrey!  
I just started the Functions course, so hopefully I can figure out a way to manipulate the full array of artworks to get the data in the right formats.

---

<div class="post-metadata">

**Author:** ![oronbz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/oronbz/32/104376_2.png) [@oronbz](https://forums.kodeco.com/u/oronbz)\
**Post date:** [December 29, 2019, 3:24pm UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774/10 "2019-12-29T15:24:10Z")

</div>

Hi!  
I’ve download the finished project and ran it in the latest Xcode: Version 11.3 (11C29)  
When tapping an item, getting into the detail screen, then going back to the main screen, and then clicking the same item again the item appears to be in selected state, and I’m not being directed to the detail screen:  
 ![image](https://files.chunter.kodeco.com/original/3X/a/d/adf3683f617b613daab490e72fd21e1cd9c98271.png)

Haven’t found a solution online, anyone have any idea why is it happening?

---

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [December 29, 2019, 6:08pm UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774/11 "2019-12-29T18:08:41Z")

</div>

Hi Oron! This is a simulator bug. I wrote a reply [here](https://forums.kodeco.com/t/chapter-4-tapping-play-bullseye-is-not-working-more-than-once/91480/2)

---

<div class="post-metadata">

**Author:** ![doremon](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/doremon/32/81494_2.png) [@doremon](https://forums.kodeco.com/u/doremon)\
**Post date:** [July 1, 2020, 9:22am UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774/12 "2020-07-01T09:22:26Z")

</div>

Hi, this is a great tut. Can I have a question about `Eager Evaluation`?  
I added a breakpoint in DetailView, at body param then I run the app. I thought once it initialise DetailView, it should stop at the breakpoint. Could you please give more example or detail? Thanks

---

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [July 2, 2020, 2:08am UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774/13 "2020-07-02T02:08:17Z")

</div>

hi Doraemon! I don’t think breakpoints in SwiftUI views work the same as in a view controller. There isn’t any “execution order” as such. That’s why I put the print statement in the Artwork `init`, so you can see all of them are “downloaded” even when their list item isn’t on screen.

The next version of SwiftUI announced at WWDC 2020 will allow lazy loading for grids and stacks. And lists will be lazy loading.

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [July 7, 2020, 4:53am UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774/14 "2020-07-07T04:53:52Z")

</div>

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [July 7, 2020, 4:53am UTC](https://forums.kodeco.com/t/swiftui-tutorial-navigation-raywenderlich-com/87774/15 "2020-07-07T04:53:55Z")

</div>

Closed on July 7, 2020, 4:53am UTC


