Navigating between multiple views with TabView
Navigation views are ideal for displaying hierarchical data because they allow users to drill down into data. However, navigation views don't work well with unrelated data. We use SwiftUI's TabView
struct for that purpose.
Getting ready
Create a new SwiftUI iOS app named UsingTabViews
.
How to do it…
We will create an app with two TabView
structs. One will display the made-up best games of 2021, while the other displays various currencies used around the world. The steps are given here:
- Create a new SwiftUI view file named
HomeView
:a. Press Command ()+ N.
b. Select SwiftUI View.
c. Click Next.
d. Enter
HomeView
in the Save as field.e. Click Finish.
- Update
HomeView.swift
to display a list of games from a string array namedgames
:let games = ["Doom", "Final F","Cyberpunk", "avengers", "animal trivia", "sudoku", "snakes and &...