Skip to content

Instantly share code, notes, and snippets.

@maxcampolo
Created August 21, 2017 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxcampolo/419334872426f0238a9b679820c1a55f to your computer and use it in GitHub Desktop.
Save maxcampolo/419334872426f0238a9b679820c1a55f to your computer and use it in GitHub Desktop.
UIResponder that finds the current first responder of an iOS application.
//
// UIResponder+FirstResponder.swift
// Thor
//
// Created by Max Campolo on 8/20/17.
// Copyright © 2017 Max Campolo. All rights reserved.
//
import Foundation
import UIKit
extension UIResponder {
private weak static var currentResponder: UIResponder?
public class var currentFirstResponder: UIResponder? {
UIResponder.currentResponder = nil
UIApplication.shared.sendAction(#selector(findFirstResponder(sender:)), to: nil, from: nil, for: nil)
return UIResponder.currentResponder
}
internal func findFirstResponder(sender: AnyObject) {
UIResponder.currentResponder = self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment