Bird
0
0

What will be the output of this SwiftUI code?

medium📝 Predict Output Q13 of 15
iOS Swift - Lists and Data Display
What will be the output of this SwiftUI code?
let fruits = ["Apple", "Banana", "Cherry"]

List(fruits, id: \.self) { fruit in
  Text(fruit)
}
AA single Text view showing all fruits concatenated
BAn empty list with no rows
CA runtime error because id is missing
DA list showing Apple, Banana, Cherry as text rows
Step-by-Step Solution
Solution:
  1. Step 1: Understand the List content

    The List uses the array fruits with id: \.self, so each fruit string is a unique row.
  2. Step 2: Predict UI output

    The List will render three rows with Text views showing "Apple", "Banana", and "Cherry" respectively.
  3. Final Answer:

    A list showing Apple, Banana, Cherry as text rows -> Option D
  4. Quick Check:

    List with array and id shows each item as row [OK]
Quick Trick: List with id: \.self shows each array item as a row [OK]
Common Mistakes:
  • Expecting concatenated text instead of separate rows
  • Forgetting to add id causing runtime error
  • Thinking list will be empty without explicit rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes