Swift - CollectionsWhich of the following is the correct syntax to insert the value 5 at index 1 in a Swift array named numbers?Anumbers.insert(5, at: 1)Bnumbers.append(5, at: 1)Cnumbers.insertAt(1, 5)Dnumbers.add(5, index: 1)Check Answer
Step-by-Step SolutionSolution:Step 1: Recall insert syntax in SwiftThe insert method uses the syntax insert(_:at:) where the first argument is the element and second is the index.Step 2: Match syntax with optionsnumbers.insert(5, at: 1) matches the correct syntax: numbers.insert(5, at: 1).Final Answer:numbers.insert(5, at: 1) -> Option AQuick Check:insert(_:at:) syntax = insert(element, at: index) [OK]Quick Trick: insert(_:at:) needs element first, then index [OK]Common Mistakes:Swapping element and index orderUsing append() with indexUsing non-existent methods like insertAt or add
Master "Collections" in Swift9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Swift Quizzes Collections - Dictionary creation and access - Quiz 4medium Data Types - Typealias for custom naming - Quiz 15hard Functions - Argument labels and parameter names - Quiz 5medium Operators and Expressions - Arithmetic operators and overflow - Quiz 4medium Optionals - Guard let for early exit - Quiz 1easy Optionals - Optional chaining with ?. - Quiz 15hard Optionals - Implicitly unwrapped optionals - Quiz 9hard Variables and Constants - Semicolons are optional behavior - Quiz 14medium Variables and Constants - Semicolons are optional behavior - Quiz 13medium Variables and Constants - String interpolation - Quiz 5medium