Skip to content

Instantly share code, notes, and snippets.

@ManWithBear
Last active July 8, 2019 11:08
Show Gist options
  • Save ManWithBear/c1422e5db2eb5ca06e5c9c3e9f288ec5 to your computer and use it in GitHub Desktop.
Save ManWithBear/c1422e5db2eb5ca06e5c9c3e9f288ec5 to your computer and use it in GitHub Desktop.
Fast way to get firstResponder
import UIKit
private weak var _currentFirstResponder: UIResponder? = nil
extension UIResponder {
class func mwb_firstResponder() -> UIResponder? {
_currentFirstResponder = nil
// If you trying send action to nil, it will automatically called on first responder
UIApplication.shared.sendAction(#selector(mwb_findFirstResponder), to: nil, from: nil, for: nil)
return _currentFirstResponder
}
@objc
func mwb_findFirstResponder() {
_currentFirstResponder = self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment