Swift - Data TypesWhich of the following is the correct way to declare and copy a string in Swift?Avar original = "Hello"; var copy = original.clone()Bvar original = "Hello"; var copy = &originalCvar original = "Hello"; var copy = original.copy()Dvar original = "Hello"; var copy = originalCheck Answer
Step-by-Step SolutionSolution:Step 1: Review Swift string assignment syntaxAssigning one string to another copies the value directly using var copy = original.Step 2: Check other options for correctnessOptions A, B, and D use invalid syntax or methods not available for Swift strings.Final Answer:var original = "Hello"; var copy = original -> Option DQuick Check:Simple assignment copies string value [OK]Quick Trick: Copy strings by simple assignment, no special methods needed [OK]Common Mistakes:Using & operator which is for pointers, not stringsTrying to call clone() or copy() which don't exist for StringConfusing Swift with other languages' string methods
Master "Data Types" in Swift9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Swift Quizzes Collections - Dictionary methods and default values - Quiz 2easy Collections - Dictionary creation and access - Quiz 12easy Collections - Array creation and type inference - Quiz 14medium Data Types - Typealias for custom naming - Quiz 6medium Data Types - Bool type and logical operators - Quiz 12easy Operators and Expressions - Comparison operators - Quiz 14medium Optionals - Optional binding with if let - Quiz 9hard Swift Basics and Runtime - Why Swift for Apple and beyond - Quiz 15hard Swift Basics and Runtime - Project structure and Swift Package Manager basics - Quiz 15hard Swift Basics and Runtime - How Swift compiles to native code - Quiz 9hard