iOS Swift - User Input and FormsYou 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 }Check Answer
Step-by-Step SolutionSolution:Step 1: Identify optional property needPhone number is optional, so it should be declared as an optional type String?.Step 2: Ensure required property is non-optionalEmail is required, so it should be a non-optional String.Final Answer:struct Contact { var email: String; var phone: String? } -> Option DQuick Check:Optional phone = String? type [OK]Quick Trick: Use ? for optional form fields [OK]Common Mistakes:Making phone non-optionalMaking email optional when requiredMaking both optional unnecessarily
Master "User Input and Forms" in iOS Swift9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepUITryChallengeBuildRecallPublish
More iOS Swift Quizzes State Management in SwiftUI - @State property wrapper - Quiz 5medium Swift Language Essentials - Functions and closures - Quiz 11easy SwiftUI Basics - Text view and modifiers - Quiz 9hard SwiftUI Basics - View protocol and body property - Quiz 7medium SwiftUI Layout - GeometryReader for adaptive layouts - Quiz 7medium SwiftUI Layout - Why layout controls visual structure - Quiz 7medium User Input and Forms - Form container - Quiz 3easy User Input and Forms - Picker and DatePicker - Quiz 6medium User Input and Forms - Stepper - Quiz 15hard iOS Basics and Setup - Xcode interface (navigator, editor, inspector) - Quiz 7medium