Last active
January 2, 2019 13:58
-
-
Save CognitiveDisson/8bea14e2578a213478f0d6d3f8d30c07 to your computer and use it in GitHub Desktop.
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
// | |
// AppDelegateHandler.swift | |
// Pods | |
// | |
// Created by Andrey Zarembo on 10.02.16. | |
// | |
// | |
import Foundation | |
public class AppDelegateHandler: NSObject, UIApplicationDelegate { | |
} |
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
// | |
// AppDelegateProxy.swift | |
// Pods | |
// | |
// Created by Andrey Zarembo on 10.02.16. | |
// | |
// | |
import Foundation | |
import UIKit | |
public class AppDelegateProxy: NSObject, UIApplicationDelegate { | |
public var handlers:[AppDelegateHandler] = [] | |
public override func respondsToSelector(aSelector: Selector) -> Bool { | |
if self.shouldForwardSelector(aSelector) { | |
for handler in self.handlers { | |
if handler.respondsToSelector(aSelector) { | |
return true | |
} | |
} | |
} | |
return NSObject.instancesRespondToSelector(aSelector) | |
} | |
public override func forwardingTargetForSelector(aSelector: Selector) -> AnyObject? { | |
for handler in self.handlers { | |
if handler.respondsToSelector(aSelector) { | |
return handler | |
} | |
} | |
return nil | |
} | |
private func shouldForwardSelector(aSelector: Selector) -> Bool { | |
return isSelector(aSelector, fromProtocol: UIApplicationDelegate.self) && | |
!isSelector(aSelector, fromProtocol: NSObjectProtocol.self) | |
} | |
private func isSelector(aSelector: Selector, fromProtocol aProtocol:Protocol) -> Bool { | |
let requiredMethod = [false,false,true,true] | |
let instanceMethod = [false,true,false,true] | |
for callVariant in 0..<4 { | |
let methodDescription = protocol_getMethodDescription(aProtocol, | |
aSelector, | |
requiredMethod[callVariant], | |
instanceMethod[callVariant]) | |
if methodDescription.types != nil && methodDescription.name != nil { | |
return true | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
swift 4.2 version: