Bird
0
0

Identify the error in this Swift struct for form data: struct FormData { var email: String var age: Int init(email: String) { self.email = email } }

medium📝 Debug Q6 of 15
iOS Swift - User Input and Forms
Identify the error in this Swift struct for form data: struct FormData { var email: String var age: Int init(email: String) { self.email = email } }
AMissing initialization of age property
Bemail property should be optional
CStruct cannot have an init method
Dage property should be a String
Step-by-Step Solution
Solution:
  1. Step 1: Check custom initializer

    The init method only sets email but does not set age.
  2. Step 2: Understand Swift initialization rules

    All properties must be initialized before the struct instance is created, so age is missing initialization.
  3. Final Answer:

    Missing initialization of age property -> Option A
  4. Quick Check:

    All properties must be initialized [OK]
Quick Trick: All properties must be set in init [OK]
Common Mistakes:
  • Thinking email should be optional
  • Believing structs can't have init
  • Confusing age type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes