Make RxImagePickerDelegateProxy subclass of RXNavigationControllerDelegateProxy

This commit is contained in:
Diogo Tridapalli 2017-04-14 09:49:43 -03:00 committed by Krunoslav Zaher
parent 0f4d1ffb78
commit a5aee86698
3 changed files with 4 additions and 53 deletions

View File

@ -14,7 +14,7 @@ import UIKit
#endif #endif
/// For more information take a look at `DelegateProxyType`. /// For more information take a look at `DelegateProxyType`.
public class RxNavigationControllerDelegateProxy open class RxNavigationControllerDelegateProxy
: DelegateProxy : DelegateProxy
, UINavigationControllerDelegate , UINavigationControllerDelegate
, DelegateProxyType { , DelegateProxyType {
@ -32,7 +32,7 @@ public class RxNavigationControllerDelegateProxy
} }
/// For more information take a look at `DelegateProxyType`. /// For more information take a look at `DelegateProxyType`.
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject { open override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
let navigationController: UINavigationController = castOrFatalError(object) let navigationController: UINavigationController = castOrFatalError(object)
return navigationController.createRxDelegateProxy() return navigationController.createRxDelegateProxy()
} }

View File

@ -15,49 +15,9 @@
import UIKit import UIKit
public class RxImagePickerDelegateProxy public class RxImagePickerDelegateProxy
: DelegateProxy : RxNavigationControllerDelegateProxy
, DelegateProxyType , UIImagePickerControllerDelegate {
, UIImagePickerControllerDelegate
, UINavigationControllerDelegate {
/**
For more information take a look at `DelegateProxyType`.
*/
public class func setCurrentDelegate(_ delegate: AnyObject?, toObject object: AnyObject) {
let imagePickerController: UIImagePickerController = castOrFatalError(object)
imagePickerController.delegate = castOptionalOrFatalError(delegate)
}
/**
For more information take a look at `DelegateProxyType`.
*/
public class func currentDelegateFor(_ object: AnyObject) -> AnyObject? {
let imagePickerController: UIImagePickerController = castOrFatalError(object)
return imagePickerController.delegate
}
} }
private func castOrFatalError<T>(_ value: Any!) -> T {
let maybeResult: T? = value as? T
guard let result = maybeResult else {
rxFatalError("Failure converting from \(value) to \(T.self)")
}
return result
}
private func castOptionalOrFatalError<T>(_ value: AnyObject?) -> T? {
if value == nil {
return nil
}
let v: T = castOrFatalError(value)
return v
}
private func rxFatalError(_ lastMessage: String) -> Never {
// The temptation to comment this line is great, but please don't, it's for your own good. The choice is yours.
fatalError(lastMessage)
}
#endif #endif

View File

@ -17,15 +17,6 @@
extension Reactive where Base: UIImagePickerController { extension Reactive where Base: UIImagePickerController {
/**
Reactive wrapper for `delegate`.
For more information take a look at `DelegateProxyType` protocol documentation.
*/
public var delegate: DelegateProxy {
return RxImagePickerDelegateProxy.proxyForObject(base)
}
/** /**
Reactive wrapper for `delegate` message. Reactive wrapper for `delegate` message.
*/ */