Bird
0
0

What output is produced when this Swift code runs after the keyboard appears?

medium📝 Predict Output Q4 of 15
iOS Swift - User Input and Forms
What output is produced when this Swift code runs after the keyboard appears?
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)

@objc func keyboardWillHide(notification: Notification) {
  print("Keyboard is hiding")
}
APrints "Keyboard is hiding" when keyboard appears
BPrints "Keyboard is hiding" when keyboard disappears
CNo output because observer is not added
DPrints "Keyboard is showing" when keyboard appears
Step-by-Step Solution
Solution:
  1. Step 1: Understand notification

    The observer listens for keyboardWillHideNotification, triggered when keyboard is about to hide.
  2. Step 2: Analyze selector

    The selector prints "Keyboard is hiding" when notification fires.
  3. Final Answer:

    Prints "Keyboard is hiding" when keyboard disappears -> Option B
  4. Quick Check:

    keyboardWillHideNotification triggers on keyboard dismissal [OK]
Quick Trick: keyboardWillHideNotification fires when keyboard hides [OK]
Common Mistakes:
  • Confusing keyboardWillShowNotification with keyboardWillHideNotification
  • Expecting output on keyboard appearance
  • Not adding observer properly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes