Swift - FunctionsWhich statement about nested functions in Swift is TRUE?ANested functions must be declared outside any other functionBNested functions cannot return valuesCNested functions are automatically executed when the outer function runsDNested functions can access variables from their enclosing functionCheck Answer
Step-by-Step SolutionSolution:Step 1: Check variable access rulesNested functions can use variables declared in their outer function because they share the same scope chain.Step 2: Evaluate other optionsNested functions can return values, must be declared inside another function, and are not executed automatically unless called.Final Answer:Nested functions can access variables from their enclosing function -> Option DQuick Check:Nested functions access outer variables = True [OK]Quick Trick: Nested functions share outer function's variables [OK]Common Mistakes:Assuming nested functions run automaticallyBelieving nested functions can't return valuesThinking nested functions are top-level
Master "Functions" in Swift9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Swift Quizzes Collections - Array iteration and enumerated - Quiz 12easy Collections - Set algebra (union, intersection, difference) - Quiz 10hard Control Flow - If and if-else statements - Quiz 4medium Data Types - Type conversion is always explicit - Quiz 1easy Operators and Expressions - Identity operators (=== and !==) - Quiz 6medium Operators and Expressions - Why operator safety matters in Swift - Quiz 3easy Operators and Expressions - Nil coalescing operator deep usage - Quiz 10hard Optionals - Force unwrapping with ! and its danger - Quiz 1easy Optionals - Multiple optional binding - Quiz 9hard Swift Basics and Runtime - Swift REPL and Playgrounds - Quiz 7medium