Bird
0
0

Given this code, what will be the output? let numbers = [10, 20, 30] List { ForEach(numbers, id: \.self) { num in Text(\"Number: \(num)\") } }

medium📝 Predict Output Q5 of 15
iOS Swift - Lists and Data Display
Given this code, what will be the output? let numbers = [10, 20, 30] List { ForEach(numbers, id: \.self) { num in Text(\"Number: \(num)\") } }
AList rows: 10, 20, 30 without prefix
BList rows: Number: 10, Number: 20, Number: 30
CList rows: Number: 10 repeated three times
DEmpty list with no rows
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the ForEach closure

    Each number is displayed with prefix "Number: " in a Text view.
  2. Step 2: Confirm output

    List shows three rows with "Number: 10", "Number: 20", "Number: 30" respectively.
  3. Final Answer:

    List rows: Number: 10, Number: 20, Number: 30 -> Option B
  4. Quick Check:

    ForEach text formatting = List rows: Number: 10, Number: 20, Number: 30 [OK]
Quick Trick: Text interpolation shows each item with prefix [OK]
Common Mistakes:
  • Ignoring prefix in output
  • Repeating first item
  • Expecting empty list

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes