Bird
0
0

Given this Swift struct and code, what will print?

medium📝 Predict Output Q13 of 15
iOS Swift - User Input and Forms
Given this Swift struct and code, what will print?
struct FormData {
  var email: String
  var subscribed: Bool
}

let data = FormData(email: "user@example.com", subscribed: true)
print(data.subscribed)
Auser@example.com
Btrue
Cfalse
DError: missing initializer
Step-by-Step Solution
Solution:
  1. Step 1: Understand struct initialization

    The struct FormData has two properties: email (String) and subscribed (Bool). The instance 'data' is created with email and subscribed values.
  2. Step 2: Check the print statement

    print(data.subscribed) outputs the Boolean value assigned, which is true.
  3. Final Answer:

    true -> Option B
  4. Quick Check:

    Accessing struct property prints its value [OK]
Quick Trick: Print struct property to see its stored value [OK]
Common Mistakes:
  • Confusing property names
  • Expecting email to print instead of subscribed
  • Thinking initialization is missing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes