Bird
0
0

How would you implement a SwiftUI TabView with three tabs named "Home", "Search", and "Profile", each showing a different view and having distinct system icons?

hard📝 navigation Q8 of 15
iOS Swift - Navigation
How would you implement a SwiftUI TabView with three tabs named "Home", "Search", and "Profile", each showing a different view and having distinct system icons?
ATabView { HomeView().tabItem { Label("Home", systemImage: "house") } SearchView().tabItem { Label("Search", systemImage: "magnifyingglass") } ProfileView().tabItem { Label("Profile", systemImage: "person.circle") } }
BTabView { HomeView().tabItem(Label("Home")) SearchView().tabItem(Label("Search")) ProfileView().tabItem(Label("Profile")) }
CTabView(selection: $selectedTab) { HomeView().tabItem { Image(systemName: "house") } SearchView().tabItem { Image(systemName: "magnifyingglass") } ProfileView().tabItem { Image(systemName: "person.circle") } }
DTabView { HomeView().tabItem { Text("Home") } SearchView().tabItem { Text("Search") } ProfileView().tabItem { Text("Profile") } }
Step-by-Step Solution
Solution:
  1. Step 1: Use .tabItem with Label

    Each tab requires a .tabItem modifier with a Label containing text and a system image.
  2. Step 2: Verify distinct views and icons

    TabView { HomeView().tabItem { Label("Home", systemImage: "house") } SearchView().tabItem { Label("Search", systemImage: "magnifyingglass") } ProfileView().tabItem { Label("Profile", systemImage: "person.circle") } } correctly assigns different views and unique system icons for each tab.
  3. Step 3: Identify incorrect options

    TabView { HomeView().tabItem(Label("Home")) SearchView().tabItem(Label("Search")) ProfileView().tabItem(Label("Profile")) } lacks system images. TabView(selection: $selectedTab) { HomeView().tabItem { Image(systemName: "house") } SearchView().tabItem { Image(systemName: "magnifyingglass") } ProfileView().tabItem { Image(systemName: "person.circle") } } uses only images without labels and misses text. TabView { HomeView().tabItem { Text("Home") } SearchView().tabItem { Text("Search") } ProfileView().tabItem { Text("Profile") } } uses only text without icons.
  4. Final Answer:

    TabView { HomeView().tabItem { Label("Home", systemImage: "house") } SearchView().tabItem { Label("Search", systemImage: "magnifyingglass") } ProfileView().tabItem { Label("Profile", systemImage: "person.circle") } } correctly implements the requirements.
  5. Quick Check:

    Use Label(text, systemImage) inside .tabItem [OK]
Quick Trick: Use Label with text and icon inside .tabItem [OK]
Common Mistakes:
  • Omitting system images in tabItem
  • Using only Image or Text inside tabItem
  • Not assigning unique views per tab

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes