Skip to content

Instantly share code, notes, and snippets.

@kylehowells
Created July 18, 2022 15:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylehowells/ef02ae5bcea27a00c4f20fba5caaccef to your computer and use it in GitHub Desktop.
Save kylehowells/ef02ae5bcea27a00c4f20fba5caaccef to your computer and use it in GitHub Desktop.
import UIKit
extension UIResponder {
private weak static var _currentFirstResponder: UIResponder? = nil
public static var current: UIResponder? {
UIResponder._currentFirstResponder = nil
UIApplication.shared.sendAction(#selector(findFirstResponder(sender:)), to: nil, from: nil, for: nil)
return UIResponder._currentFirstResponder
}
@objc internal func findFirstResponder(sender: AnyObject) {
UIResponder._currentFirstResponder = self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment