Last active
July 25, 2016 14:36
-
-
Save sjgroomi/2a30c9b1447736aa66e5 to your computer and use it in GitHub Desktop.
Get the current first responder
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.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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?