Bird
0
0

Why does the Swift subtracting() method return a new set instead of modifying the original set?

hard📝 Conceptual Q10 of 15
Swift - Collections
Why does the Swift subtracting() method return a new set instead of modifying the original set?
ABecause sets are value types and methods return new copies
BBecause sets cannot be changed once created
CBecause subtracting() is a static method
DBecause Swift does not support mutable collections
Step-by-Step Solution
Solution:
  1. Step 1: Understand Swift sets as value types

    Swift sets are value types, so methods like subtracting() return new sets instead of changing originals.
  2. Step 2: Confirm other options are incorrect

    Sets can be mutable, subtracting() is an instance method, and Swift supports mutable collections.
  3. Final Answer:

    Because sets are value types and methods return new copies -> Option A
  4. Quick Check:

    Value types return new copies, not modify originals [OK]
Quick Trick: Sets are value types; methods return new sets [OK]
Common Mistakes:
  • Thinking sets are immutable
  • Confusing instance and static methods
  • Assuming Swift collections are always immutable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes