Bird
0
0

What will be displayed when this SwiftUI code runs?

medium📝 Predict Output Q4 of 15
iOS Swift - Lists and Data Display
What will be displayed when this SwiftUI code runs?
let animals = ["Cat", "Dog", "Bird"]

var body: some View {
  List(animals, id: \.self) { animal in
    Text(animal)
  }
}
AA scrollable list showing Cat, Dog, Bird
BA single Text view showing all animals concatenated
CAn empty screen with no content
DA runtime error due to missing id
Step-by-Step Solution
Solution:
  1. Step 1: Analyze List usage

    The List uses the animals array with id: \.self, so each string is uniquely identified.
  2. Step 2: Expected UI output

    The List will show each animal as a separate Text view in a scrollable list.
  3. Final Answer:

    A scrollable list showing Cat, Dog, Bird -> Option A
  4. Quick Check:

    List with array = scrollable list [OK]
Quick Trick: List shows each array item as a separate row [OK]
Common Mistakes:
  • Expecting concatenated text
  • Thinking List needs extra code to scroll
  • Assuming runtime error without id

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes