Coding⏱️ 2 min read📅 2026-06-03

How to Fix: Easy way to dismiss keyboard?

Dismiss keyboard without looping through controls

Quick Answer: Use the ` resignFirstResponder()` method for iOS or `requestFocus(false)` for Android to get the current first responder.

To dismiss the keyboard without having to loop through all your controls and resign them all as the first responder, you can use the removeFromResponder method on the current first responder.

💡 How to Get the Current First Responder

  • Use the firstResponder property on the current view controller:

    [ViewController] @objc var firstResponder: UIResponder? = nil override func viewDidLoad() { super.viewDidLoad() firstResponder = self.view.window?.rootViewController?.currentFirstResponder() }

🔧 Dismissing the Keyboard

Method:

  1. Step 1: Get the current first responder:

    [ViewController] @objc var firstResponder: UIResponder? = nil override func viewDidLoad() { super.viewDidLoad() firstResponder = self.view.window?.rootViewController?.currentFirstResponder() }
  2. Step 2: Call the removeFromResponder method on the current first responder:

    [ViewController] override func viewDidLoad() { super.viewDidLoad() if let responder = self.view.window?.rootViewController?.currentFirstResponder() { responder.removeFromResponder() }

🎯 Final Words

By following these steps, you can easily dismiss the keyboard without having to resign all your controls.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions