Last active
July 8, 2019 11:08
-
-
Save ManWithBear/c1422e5db2eb5ca06e5c9c3e9f288ec5 to your computer and use it in GitHub Desktop.
Fast way to get firstResponder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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