Bird
0
0

Why is the addTarget(_:action:for:) method preferred over delegates for handling UISwitch toggle events?

hard📝 Conceptual Q10 of 15
iOS Swift - User Input and Forms
Why is the addTarget(_:action:for:) method preferred over delegates for handling UISwitch toggle events?
ABecause <code>UISwitch</code> uses target-action pattern for event handling, not delegates
BBecause delegates are deprecated in iOS for UI controls
CBecause <code>UISwitch</code> cannot detect user interactions without addTarget
DBecause addTarget allows multiple delegates to be assigned
Step-by-Step Solution
Solution:
  1. Step 1: Understand event handling patterns

    UIKit controls like UISwitch use target-action pattern, not delegates.
  2. Step 2: Clarify delegate usage

    Delegates are used in other contexts but not for UISwitch toggle events.
  3. Step 3: Evaluate other options

    B is false, delegates are not deprecated; C is incorrect, UISwitch can detect interactions but uses target-action; D is false, addTarget does not assign delegates.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    UISwitch uses target-action, not delegates [OK]
Quick Trick: UISwitch uses target-action, not delegate pattern [OK]
Common Mistakes:
  • Assuming delegates handle UISwitch events
  • Believing delegates are deprecated for UI controls

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes