Swift - OptionalsWhy does optional chaining return an optional value even if the property accessed is non-optional?ABecause Swift always wraps property values in optionals.BBecause the chain might fail if any optional in the chain is nil, so result is optional.CBecause optional chaining forces unwrapping internally.DBecause the property is automatically converted to optional type.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand optional chaining behaviorOptional chaining returns nil if any optional in the chain is nil, so the result must be optional.Step 2: Clarify why result is optionalEven if the property itself is non-optional, the chain might fail, so Swift wraps the result in an optional.Final Answer:Because the chain might fail if any optional in the chain is nil, so result is optional. -> Option BQuick Check:Optional chaining returns optional result due to possible nil [OK]Quick Trick: Optional chaining returns optional because chain can fail [OK]Common Mistakes:Thinking property is always optionalAssuming forced unwrap happensBelieving Swift converts all properties to optional
Master "Optionals" in Swift9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Swift Quizzes Control Flow - No implicit fallthrough in switch - Quiz 13medium Control Flow - Guard for early exit pattern - Quiz 10hard Functions - Why functions are first-class in Swift - Quiz 9hard Functions - Function declaration syntax - Quiz 15hard Loops - Labeled statements for nested loops - Quiz 15hard Loops - For-in loop with collections - Quiz 1easy Operators and Expressions - Logical operators - Quiz 4medium Optionals - Nil coalescing operator (??) - Quiz 11easy Variables and Constants - String interpolation - Quiz 4medium Variables and Constants - Semicolons are optional behavior - Quiz 4medium