Bird
0
0

Which code snippet correctly implements this with minimal repetition?

hard📝 navigation Q15 of 15
iOS Swift - Navigation
You want to create a TabView with three tabs: Home, Search, and Profile. Each tab should show a different view and have a label with a system icon. Which code snippet correctly implements this with minimal repetition?
ATabView { HomeView().tabItem { Text("Home") } SearchView().tabItem { Text("Search") } ProfileView().tabItem { Text("Profile") } }
BTabView { HomeView().tabItem(Label("Home", systemImage: "house")) SearchView().tabItem(Label("Search", systemImage: "magnifyingglass")) ProfileView().tabItem(Label("Profile", systemImage: "person")) }
CTabView { HomeView().tabItem { Label("Home", systemImage: "house") } SearchView().tabItem { Label("Search", systemImage: "magnifyingglass") } ProfileView().tabItem { Label("Profile", systemImage: "person") } }
DTabView { HomeView().tabItem { Label("Home") } SearchView().tabItem { Label("Search") } ProfileView().tabItem { Label("Profile") } }
Step-by-Step Solution
Solution:
  1. Step 1: Check tabItem syntax for each tab

    TabView { HomeView().tabItem { Label("Home", systemImage: "house") } SearchView().tabItem { Label("Search", systemImage: "magnifyingglass") } ProfileView().tabItem { Label("Profile", systemImage: "person") } } correctly uses braces with Label including both text and systemImage for each tab.
  2. Step 2: Review other options for errors

    TabView { HomeView().tabItem(Label("Home", systemImage: "house")) SearchView().tabItem(Label("Search", systemImage: "magnifyingglass")) ProfileView().tabItem(Label("Profile", systemImage: "person")) } misses braces, causing syntax errors. TabView { HomeView().tabItem { Text("Home") } SearchView().tabItem { Text("Search") } ProfileView().tabItem { Text("Profile") } } uses Text instead of Label, so no icons. TabView { HomeView().tabItem { Label("Home") } SearchView().tabItem { Label("Search") } ProfileView().tabItem { Label("Profile") } } uses Label without systemImage, so no icons.
  3. Final Answer:

    TabView { HomeView().tabItem { Label("Home", systemImage: "house") } SearchView().tabItem { Label("Search", systemImage: "magnifyingglass") } ProfileView().tabItem { Label("Profile", systemImage: "person") } } -> Option C
  4. Quick Check:

    Use Label with text and systemImage inside braces for tabItem [OK]
Quick Trick: Use Label with text and systemImage inside braces for tabs [OK]
Common Mistakes:
  • Omitting braces {} around tabItem content
  • Using Text instead of Label for icons
  • Forgetting systemImage parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes