Bird
0
0

Given this code snippet, what will be displayed?

medium📝 Predict Output Q13 of 15
iOS Swift - SwiftUI Layout
Given this code snippet, what will be displayed?
struct ContentView: View {
  let numbers = [1, 2, 3]
  var body: some View {
    List(numbers, id: \.self) { num in
      Text("Number: \(num * 2)")
    }
  }
}
ANumber: 1, Number: 4, Number: 9
BNumber: 1, Number: 2, Number: 3
CNumber: 2, Number: 4, Number: 6
DNumber: 0, Number: 1, Number: 2
Step-by-Step Solution
Solution:
  1. Step 1: Understand the data and transformation

    The array contains 1, 2, 3. Each number is multiplied by 2 in the Text view.
  2. Step 2: Calculate displayed values

    1*2=2, 2*2=4, 3*2=6, so the list shows "Number: 2", "Number: 4", "Number: 6".
  3. Final Answer:

    Number: 2, Number: 4, Number: 6 -> Option C
  4. Quick Check:

    Multiply each number by 2 = A [OK]
Quick Trick: Check how data transforms inside Text closure [OK]
Common Mistakes:
  • Ignoring the multiplication inside the string
  • Confusing array values with displayed text
  • Assuming original numbers are shown

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes