Created
August 21, 2017 14:08
-
-
Save maxcampolo/419334872426f0238a9b679820c1a55f to your computer and use it in GitHub Desktop.
UIResponder that finds the current first responder of an iOS application.
This file contains 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
// | |
// 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