Bird
0
0

You want to capture a user's contact info in a form with optional phone number. Which struct design correctly models this?

hard📝 Application Q8 of 15
iOS Swift - User Input and Forms
You want to capture a user's contact info in a form with optional phone number. Which struct design correctly models this?
Astruct Contact { var email: String?; var phone: String? }
Bstruct Contact { var email: String; var phone: String? }
Cstruct Contact { var email: String?; var phone: String }
Dstruct Contact { var email: String; var phone: String }
Step-by-Step Solution
Solution:
  1. Step 1: Identify optional property need

    Phone number is optional, so it should be declared as an optional type String?.
  2. Step 2: Ensure required property is non-optional

    Email is required, so it should be a non-optional String.
  3. Final Answer:

    struct Contact { var email: String; var phone: String? } -> Option D
  4. Quick Check:

    Optional phone = String? type [OK]
Quick Trick: Use ? for optional form fields [OK]
Common Mistakes:
  • Making phone non-optional
  • Making email optional when required
  • Making both optional unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes