Bird
0
0

Which of the following code snippets correctly creates a TabView with two tabs labeled "Dashboard" and "Settings" in SwiftUI?

easy📝 Syntax Q3 of 15
iOS Swift - Navigation
Which of the following code snippets correctly creates a TabView with two tabs labeled "Dashboard" and "Settings" in SwiftUI?
ATabView { Text("Dashboard").tabItem { Label("Dashboard", systemImage: "speedometer") } Text("Settings").tabItem { Label("Settings", systemImage: "gear") } }
BTabView { Text("Dashboard") Text("Settings") }.tabItem { Label("Dashboard", systemImage: "speedometer") }
CTabView { Text("Dashboard").tabItem(Label("Dashboard")) Text("Settings").tabItem(Label("Settings")) }
DTabView { Text("Dashboard").tabItem { Image(systemName: "speedometer") } Text("Settings").tabItem { Image(systemName: "gear") } }
Step-by-Step Solution
Solution:
  1. Step 1: Check tabItem usage

    The .tabItem modifier requires a label with text and optionally an image.
  2. Step 2: Validate syntax

    TabView { Text("Dashboard").tabItem { Label("Dashboard", systemImage: "speedometer") } Text("Settings").tabItem { Label("Settings", systemImage: "gear") } } correctly uses Label with text and system image inside tabItem.
  3. Step 3: Identify incorrect options

    TabView { Text("Dashboard") Text("Settings") }.tabItem { Label("Dashboard", systemImage: "speedometer") } applies tabItem to the whole TabView, which is invalid. TabView { Text("Dashboard").tabItem(Label("Dashboard")) Text("Settings").tabItem(Label("Settings")) } misses system images. TabView { Text("Dashboard").tabItem { Image(systemName: "speedometer") } Text("Settings").tabItem { Image(systemName: "gear") } } uses only images without labels.
  4. Final Answer:

    TabView { Text("Dashboard").tabItem { Label("Dashboard", systemImage: "speedometer") } Text("Settings").tabItem { Label("Settings", systemImage: "gear") } } is syntactically correct.
  5. Quick Check:

    tabItem needs Label with text and image [OK]
Quick Trick: Use .tabItem with Label(text, systemImage) [OK]
Common Mistakes:
  • Applying tabItem to TabView instead of child views
  • Omitting systemImage in Label
  • Using only Image without text in tabItem

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes