Skip to content

Instantly share code, notes, and snippets.

@sjgroomi
Last active July 25, 2016 14:36
Show Gist options
  • Save sjgroomi/2a30c9b1447736aa66e5 to your computer and use it in GitHub Desktop.
Save sjgroomi/2a30c9b1447736aa66e5 to your computer and use it in GitHub Desktop.
Get the current first responder
//
// UIResponder.swift
//
// Created by Groom on 23/03/2015.
// Copyright (c) 2015 Stephen Groom. All rights reserved.
//
import UIKit
extension UIResponder {
//Class var not supported in 1.0
private struct CurrentFirstResponder {
weak static var currentFirstResponder: UIResponder?
}
private class var currentFirstResponder: UIResponder? {
get { return CurrentFirstResponder.currentFirstResponder }
set(newValue) { CurrentFirstResponder.currentFirstResponder = newValue }
}
class func getCurrentFirstResponder() -> UIResponder? {
currentFirstResponder = nil
UIApplication.sharedApplication().sendAction("findFirstResponder", to: nil, from: nil, forEvent: nil)
return currentFirstResponder
}
func findFirstResponder() {
UIResponder.currentFirstResponder = self
}
}
@sumate-sdk
Copy link

Hi I'm new in Swift but I wish to understand how this work. Can you give me an advice what I have to read to understand this process?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment