Bird
0
0

What will this SwiftUI view display when the tasks array is empty?

medium📝 Predict Output Q4 of 15
iOS Swift - Lists and Data Display
What will this SwiftUI view display when the tasks array is empty?
var body: some View {
  if tasks.isEmpty {
    Text("No tasks available")
  } else {
    List(tasks, id: \.self) { task in
      Text(task)
    }
  }
}
AA text label saying "No tasks available"
BAn empty list with no rows
CA runtime error due to empty array
DA blank screen with no content
Step-by-Step Solution
Solution:
  1. Step 1: Analyze condition

    The code checks if tasks.isEmpty and shows a Text view if true.
  2. Step 2: Determine output

    When tasks is empty, the Text("No tasks available") is displayed.
  3. Final Answer:

    A text label saying "No tasks available" -> Option A
  4. Quick Check:

    Empty array triggers the Text view [OK]
Quick Trick: Empty arrays show the Text view in if condition [OK]
Common Mistakes:
  • Assuming an empty List is shown
  • Expecting a runtime error
  • Thinking the screen is blank

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes