Skip to content

Instantly share code, notes, and snippets.

@RustyKnight
Created August 29, 2018 22:06
Show Gist options
  • Save RustyKnight/dcafdae3638b7c90bb24b4646d7c7c7f to your computer and use it in GitHub Desktop.
Save RustyKnight/dcafdae3638b7c90bb24b4646d7c7c7f to your computer and use it in GitHub Desktop.
Extension to find which view is currently the first responder - this only works if the responder is the current view or a child of the current view
import Foundation
import UIKit
extension UIView {
var firstResponder: UIView? {
guard !isFirstResponder else {
return self
}
for view in subviews {
guard let responder = view.firstResponder else {
continue
}
return responder
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment