Skip to content

Instantly share code, notes, and snippets.

@MojtabaHs
Created December 4, 2020 22:24
Show Gist options
  • Save MojtabaHs/ea4935263be4bd28a193fe879ec5d0eb to your computer and use it in GitHub Desktop.
Save MojtabaHs/ea4935263be4bd28a193fe879ec5d0eb to your computer and use it in GitHub Desktop.
Finds and returns the next responder with the given condition.
extension UIResponder {
func nextFirstResponder(where condition: (UIResponder) -> Bool ) -> UIResponder? {
guard let next = next else { return nil }
if condition(next) { return next }
else { return next.nextFirstResponder(where: condition) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment