implement DelegateProxy factory

This commit is contained in:
tarunon 2017-06-17 01:20:54 +09:00
parent 16eabd5ea4
commit 3fba185b96
29 changed files with 141 additions and 296 deletions

View File

@ -188,13 +188,6 @@ open class DelegateProxy : _RXDelegateProxy {
return delegateAssociatedTag
}
/// Initializes new instance of delegate proxy.
///
/// - returns: Initialized instance of `self`.
open class func createProxyForObject(_ object: AnyObject) -> AnyObject {
return self.init(parentObject: object)
}
/// Returns assigned proxy for object.
///
/// - parameter object: Object that can have assigned delegate proxy.

View File

@ -69,22 +69,25 @@ every view has a corresponding delegate virtual factory method.
In case of UITableView / UIScrollView, there is
extension UIScrollView {
public func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
return RxScrollViewDelegateProxy(parentObject: base)
}
RxScrollViewDelegateProxy has factories that contains RxScrollViewDelegateProxy(parentObject: parentObject)
....
and override in UITableView
and extend it
extension UITableView {
public override func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
....
RxScrollViewDelegateProxy.extend { (parentObject: UITableView) in
RxTableViewDelegateProxy(parentObject: parentObject)
}
*/
public protocol DelegateProxyType : AnyObject {
/// DelegateProxy factory
static var factories: [((AnyObject) -> AnyObject?)] { get set }
/// Extend DelegateProxy for specific subclass
static func extend<Object: AnyObject>(with factory: @escaping ((Object) -> AnyObject))
/// Creates new proxy for target object.
static func createProxyForObject(_ object: AnyObject) -> AnyObject
@ -210,6 +213,14 @@ extension DelegateProxyType {
proxy.setForwardToDelegate(nil, retainDelegate: retainDelegate)
}
}
public static func extend<Object: AnyObject>(with factory: @escaping ((Object) -> AnyObject)) {
factories.append({ ($0 as? Object).map(factory) })
}
public static func createProxyForObject(_ object: AnyObject) -> AnyObject {
return factories.reversed().reduce(AnyObject?.none) { $0 ?? $1(object) }!
}
}
#if os(iOS) || os(tvOS)

View File

@ -11,15 +11,6 @@
import RxSwift
#endif
import UIKit
extension NSTextStorage {
/// Factory method that enables subclasses to implement their own `delegate`.
///
/// - returns: Instance of delegate proxy that wraps `delegate`.
public func createRxDelegateProxy() -> RxTextStorageDelegateProxy {
return RxTextStorageDelegateProxy(parentObject: self)
}
}
extension Reactive where Base: NSTextStorage {

View File

@ -35,7 +35,11 @@ final class CollectionViewDataSourceNotSet
public class RxCollectionViewDataSourceProxy
: DelegateProxy
, UICollectionViewDataSource
, DelegateProxyType {
, DelegateProxyType {
public static var factories: [((AnyObject) -> AnyObject?)] = [
{ RxCollectionViewDataSourceProxy(parentObject: $0) }
]
/// Typed parent object.
public weak private(set) var collectionView: UICollectionView?
@ -64,12 +68,6 @@ public class RxCollectionViewDataSourceProxy
// MARK: proxy
/// For more information take a look at `DelegateProxyType`.
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
let collectionView: UICollectionView = castOrFatalError(object)
return collectionView.createRxDataSourceProxy()
}
/// For more information take a look at `DelegateProxyType`.
public override class func delegateAssociatedObjectTag() -> UnsafeRawPointer {
return dataSourceAssociatedTag

View File

@ -18,6 +18,10 @@
: DelegateProxy
, UINavigationControllerDelegate
, DelegateProxyType {
public static var factories: [((AnyObject) -> AnyObject?)] = [
{ RxNavigationControllerDelegateProxy(parentObject: $0) }
]
/// For more information take a look at `DelegateProxyType`.
public class func currentDelegateFor(_ object: AnyObject) -> AnyObject? {
@ -30,12 +34,6 @@
let navigationController: UINavigationController = castOrFatalError(object)
navigationController.delegate = castOptionalOrFatalError(delegate)
}
/// For more information take a look at `DelegateProxyType`.
open override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
let navigationController: UINavigationController = castOrFatalError(object)
return navigationController.createRxDelegateProxy()
}
}
#if os(iOS)

View File

@ -17,12 +17,10 @@
: DelegateProxy
, DelegateProxyType
, UIPickerViewDelegate {
/// For more information take a look at `DelegateProxyType`.
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
let pickerView: UIPickerView = castOrFatalError(object)
return pickerView.createRxDelegateProxy()
}
public static var factories: [((AnyObject) -> AnyObject?)] = [
{ RxPickerViewDelegateProxy(parentObject: $0) }
]
/// For more information take a look at `DelegateProxyType`.
public class func setCurrentDelegate(_ delegate: AnyObject?, toObject object: AnyObject) {

View File

@ -18,6 +18,13 @@ public class RxScrollViewDelegateProxy
: DelegateProxy
, UIScrollViewDelegate
, DelegateProxyType {
public static var factories: [((AnyObject) -> AnyObject?)] = [
{ RxScrollViewDelegateProxy(parentObject: $0) },
{ ($0 as? UITableView).map { RxTableViewDelegateProxy(parentObject: $0) } },
{ ($0 as? UICollectionView).map { RxCollectionViewDelegateProxy(parentObject: $0) } },
{ ($0 as? UITextView).map { RxTextViewDelegateProxy(parentObject: $0) } }
]
fileprivate var _contentOffsetBehaviorSubject: BehaviorSubject<CGPoint>?
fileprivate var _contentOffsetPublishSubject: PublishSubject<()>?
@ -72,12 +79,6 @@ public class RxScrollViewDelegateProxy
// MARK: delegate proxy
/// For more information take a look at `DelegateProxyType`.
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
let scrollView: UIScrollView = castOrFatalError(object)
return scrollView.createRxDelegateProxy()
}
/// For more information take a look at `DelegateProxyType`.
public class func setCurrentDelegate(_ delegate: AnyObject?, toObject object: AnyObject) {
let scrollView: UIScrollView = castOrFatalError(object)

View File

@ -19,6 +19,12 @@ public class RxSearchBarDelegateProxy
, UISearchBarDelegate
, DelegateProxyType {
// MARK: Delegate proxy methods
public static var factories: [((AnyObject) -> AnyObject?)] = [
{ RxSearchBarDelegateProxy(parentObject: $0) }
]
/// For more information take a look at `DelegateProxyType`.
public class func currentDelegateFor(_ object: AnyObject) -> AnyObject? {
let searchBar: UISearchBar = castOrFatalError(object)
@ -30,17 +36,6 @@ public class RxSearchBarDelegateProxy
let searchBar: UISearchBar = castOrFatalError(object)
searchBar.delegate = castOptionalOrFatalError(delegate)
}
// MARK: Delegate proxy methods
#if os(iOS)
/// For more information take a look at `DelegateProxyType`.
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
let searchBar: UISearchBar = castOrFatalError(object)
return searchBar.createRxDelegateProxy()
}
#endif
}
#endif

View File

@ -18,13 +18,11 @@
public class RxSearchControllerDelegateProxy
: DelegateProxy
, DelegateProxyType
, UISearchControllerDelegate {
/// For more information take a look at `DelegateProxyType`.
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
let pickerView: UISearchController = castOrFatalError(object)
return pickerView.createRxDelegateProxy()
}
, UISearchControllerDelegate {
public static var factories: [((AnyObject) -> AnyObject?)] = [
{ RxSearchControllerDelegateProxy(parentObject: $0) }
]
/// For more information take a look at `DelegateProxyType`.
public class func setCurrentDelegate(_ delegate: AnyObject?, toObject object: AnyObject) {

View File

@ -19,6 +19,10 @@ public class RxTabBarControllerDelegateProxy
, UITabBarControllerDelegate
, DelegateProxyType {
public static var factories: [((AnyObject) -> AnyObject?)] = [
{ RxTabBarControllerDelegateProxy(parentObject: $0) }
]
/// For more information take a look at `DelegateProxyType`.
public class func currentDelegateFor(_ object: AnyObject) -> AnyObject? {
let tabBarController: UITabBarController = castOrFatalError(object)
@ -30,12 +34,6 @@ public class RxTabBarControllerDelegateProxy
let tabBarController: UITabBarController = castOrFatalError(object)
tabBarController.delegate = castOptionalOrFatalError(delegate)
}
/// For more information take a look at `DelegateProxyType`.
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
let tabBarController: UITabBarController = castOrFatalError(object)
return tabBarController.createRxDelegateProxy()
}
}
#endif

View File

@ -18,6 +18,10 @@ public class RxTabBarDelegateProxy
: DelegateProxy
, UITabBarDelegate
, DelegateProxyType {
public static var factories: [((AnyObject) -> AnyObject?)] = [
{ RxTabBarDelegateProxy(parentObject: $0) }
]
/// For more information take a look at `DelegateProxyType`.
public class func currentDelegateFor(_ object: AnyObject) -> AnyObject? {
@ -30,13 +34,6 @@ public class RxTabBarDelegateProxy
let tabBar: UITabBar = castOrFatalError(object)
tabBar.delegate = castOptionalOrFatalError(delegate)
}
/// For more information take a look at `DelegateProxyType`.
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
let tabBar: UITabBar = castOrFatalError(object)
return tabBar.createRxDelegateProxy()
}
}
#endif

View File

@ -33,6 +33,10 @@ public class RxTableViewDataSourceProxy
: DelegateProxy
, UITableViewDataSource
, DelegateProxyType {
public static var factories: [((AnyObject) -> AnyObject?)] = [
{ RxTableViewDataSourceProxy(parentObject: $0) }
]
/// Typed parent object.
public weak fileprivate(set) var tableView: UITableView?
@ -61,12 +65,6 @@ public class RxTableViewDataSourceProxy
// MARK: proxy
/// For more information take a look at `DelegateProxyType`.
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
let tableView: UITableView = castOrFatalError(object)
return tableView.createRxDataSourceProxy()
}
/// For more information take a look at `DelegateProxyType`.
public override class func delegateAssociatedObjectTag() -> UnsafeRawPointer {
return dataSourceAssociatedTag

View File

@ -16,13 +16,11 @@
public class RxTextStorageDelegateProxy
: DelegateProxy
, DelegateProxyType
, NSTextStorageDelegate {
/// For more information take a look at `DelegateProxyType`.
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
let pickerView: NSTextStorage = castOrFatalError(object)
return pickerView.createRxDelegateProxy()
}
, NSTextStorageDelegate {
public static var factories: [((AnyObject) -> AnyObject?)] = [
{ RxTextStorageDelegateProxy(parentObject: $0) }
]
/// For more information take a look at `DelegateProxyType`.
public class func setCurrentDelegate(_ delegate: AnyObject?, toObject object: AnyObject) {

View File

@ -17,13 +17,11 @@ public class RxWebViewDelegateProxy
: DelegateProxy
, DelegateProxyType
, UIWebViewDelegate {
/// For more information take a look at `DelegateProxyType`.
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
let pickerView: UIWebView = castOrFatalError(object)
return pickerView.createRxDelegateProxy()
}
public static var factories: [((AnyObject) -> AnyObject?)] = [
{ RxWebViewDelegateProxy(parentObject: $0) }
]
/// For more information take a look at `DelegateProxyType`.
public class func setCurrentDelegate(_ delegate: AnyObject?, toObject object: AnyObject) {
let webView: UIWebView = castOrFatalError(object)

View File

@ -160,17 +160,6 @@ extension Reactive where Base: UICollectionView {
}
}
extension UICollectionView {
/// Factory method that enables subclasses to implement their own `rx.dataSource`.
///
/// - returns: Instance of delegate proxy that wraps `dataSource`.
public func createRxDataSourceProxy() -> RxCollectionViewDataSourceProxy {
return RxCollectionViewDataSourceProxy(parentObject: self)
}
}
extension Reactive where Base: UICollectionView {
/// Reactive wrapper for `dataSource`.

View File

@ -13,15 +13,6 @@ import RxSwift
#endif
import UIKit
extension UINavigationController {
/// Factory method that enables subclasses to implement their own `delegate`.
///
/// - returns: Instance of delegate proxy that wraps `delegate`.
public func createRxDelegateProxy() -> RxNavigationControllerDelegateProxy {
return RxNavigationControllerDelegateProxy(parentObject: self)
}
}
extension Reactive where Base: UINavigationController {
public typealias ShowEvent = (viewController: UIViewController, animated: Bool)

View File

@ -13,17 +13,6 @@
#endif
import UIKit
extension UIPickerView {
/// Factory method that enables subclasses to implement their own `delegate`.
///
/// - returns: Instance of delegate proxy that wraps `delegate`.
public func createRxDelegateProxy() -> RxPickerViewDelegateProxy {
return RxPickerViewDelegateProxy(parentObject: self)
}
}
extension Reactive where Base: UIPickerView {
/// Reactive wrapper for `delegate`.

View File

@ -14,26 +14,6 @@
import UIKit
extension UIScrollView {
/// Factory method that enables subclasses to implement their own `delegate`.
///
/// - returns: Instance of delegate proxy that wraps `delegate`.
public func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
switch self {
case self as UICollectionView:
return RxCollectionViewDelegateProxy(parentObject: self)
case self as UITableView:
return RxTableViewDelegateProxy(parentObject: self)
case self as UITextView:
return RxTextViewDelegateProxy(parentObject: self)
default:
return RxScrollViewDelegateProxy(parentObject: self)
}
}
}
extension Reactive where Base: UIScrollView {
/// Reactive wrapper for `delegate`.

View File

@ -13,19 +13,6 @@ import RxSwift
#endif
import UIKit
#if os(iOS)
extension UISearchBar {
/// Factory method that enables subclasses to implement their own `delegate`.
///
/// - returns: Instance of delegate proxy that wraps `delegate`.
public func createRxDelegateProxy() -> RxSearchBarDelegateProxy {
return RxSearchBarDelegateProxy(parentObject: self)
}
}
#endif
extension Reactive where Base: UISearchBar {
/// Reactive wrapper for `delegate`.

View File

@ -12,15 +12,6 @@
import RxSwift
#endif
import UIKit
extension UISearchController {
/// Factory method that enables subclasses to implement their own `delegate`.
///
/// - returns: Instance of delegate proxy that wraps `delegate`.
public func createRxDelegateProxy() -> RxSearchControllerDelegateProxy {
return RxSearchControllerDelegateProxy(parentObject: self)
}
}
@available(iOS 8.0, *)
extension Reactive where Base: UISearchController {

View File

@ -70,17 +70,7 @@ extension Reactive where Base: UITabBar {
/**
iOS and tvOS
*/
extension UITabBar {
/// Factory method that enables subclasses to implement their own `delegate`.
///
/// - returns: Instance of delegate proxy that wraps `delegate`.
public func createRxDelegateProxy() -> RxTabBarDelegateProxy {
return RxTabBarDelegateProxy(parentObject: self)
}
}
extension Reactive where Base: UITabBar {
/// Reactive wrapper for `delegate`.
///

View File

@ -58,16 +58,6 @@ extension Reactive where Base: UITabBarController {
/**
iOS and tvOS
*/
extension UITabBarController {
/// Factory method that enables subclasses to implement their own `delegate`.
///
/// - returns: Instance of delegate proxy that wraps `delegate`.
public func createRxDelegateProxy() -> RxTabBarControllerDelegateProxy {
return RxTabBarControllerDelegateProxy(parentObject: self)
}
}
extension Reactive where Base: UITabBarController {
/// Reactive wrapper for `delegate`.

View File

@ -165,19 +165,6 @@ extension Reactive where Base: UITableView {
}
extension UITableView {
/**
Factory method that enables subclasses to implement their own `rx.dataSource`.
- returns: Instance of delegate proxy that wraps `dataSource`.
*/
public func createRxDataSourceProxy() -> RxTableViewDataSourceProxy {
return RxTableViewDataSourceProxy(parentObject: self)
}
}
extension Reactive where Base: UITableView {
/**
Reactive wrapper for `dataSource`.

View File

@ -14,17 +14,6 @@ import UIKit
import RxSwift
#endif
extension UIWebView {
/// Factory method that enables subclasses to implement their own `delegate`.
///
/// - returns: Instance of delegate proxy that wraps `delegate`.
public func createRxDelegateProxy() -> RxWebViewDelegateProxy {
return RxWebViewDelegateProxy(parentObject: self)
}
}
extension Reactive where Base: UIWebView {
/// Reactive wrapper for `delegate`.

View File

@ -20,6 +20,10 @@ public class RxTextFieldDelegateProxy
: DelegateProxy
, NSTextFieldDelegate
, DelegateProxyType {
public static var factories: [((AnyObject) -> AnyObject?)] = [
{ RxTextFieldDelegateProxy(parentObject: $0) }
]
fileprivate let textSubject = PublishSubject<String?>()
@ -45,12 +49,6 @@ public class RxTextFieldDelegateProxy
// MARK: Delegate proxy methods
/// For more information take a look at `DelegateProxyType`.
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
let control: NSTextField = castOrFatalError(object)
return control.createRxDelegateProxy()
}
/// For more information take a look at `DelegateProxyType`.
public class func currentDelegateFor(_ object: AnyObject) -> AnyObject? {
let textField: NSTextField = castOrFatalError(object)
@ -65,16 +63,6 @@ public class RxTextFieldDelegateProxy
}
extension NSTextField {
/// Factory method that enables subclasses to implement their own `delegate`.
///
/// - returns: Instance of delegate proxy that wraps `delegate`.
public func createRxDelegateProxy() -> RxTextFieldDelegateProxy {
return RxTextFieldDelegateProxy(parentObject: self)
}
}
extension Reactive where Base: NSTextField {
/// Reactive wrapper for `delegate`.

View File

@ -15,6 +15,10 @@ import CoreLocation
class RxCLLocationManagerDelegateProxy : DelegateProxy
, CLLocationManagerDelegate
, DelegateProxyType {
static var factories: [((AnyObject) -> AnyObject?)] = [
{ RxCLLocationManagerDelegateProxy(parentObject: $0) }
]
internal lazy var didUpdateLocationsSubject = PublishSubject<[CLLocation]>()
internal lazy var didFailWithErrorSubject = PublishSubject<Error>()

View File

@ -32,10 +32,6 @@ class ExtendNSTextFieldDelegateProxy
final class NSTextFieldSubclass
: NSTextField
, TestDelegateControl {
override func createRxDelegateProxy() -> RxTextFieldDelegateProxy {
return ExtendNSTextFieldDelegateProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
(delegate as! TestDelegateProtocol).testEventHappened?(value)
}

View File

@ -120,10 +120,6 @@ final class ExtendTableViewDelegateProxy
final class UITableViewSubclass1
: UITableView
, TestDelegateControl {
override func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
return ExtendTableViewDelegateProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
(delegate as! TestDelegateProtocol).testEventHappened?(value)
}
@ -151,10 +147,7 @@ final class ExtendTableViewDataSourceProxy
final class UITableViewSubclass2
: UITableView
, TestDelegateControl {
override func createRxDataSourceProxy() -> RxTableViewDataSourceProxy {
return ExtendTableViewDataSourceProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
if dataSource != nil {
(dataSource as! TestDelegateProtocol).testEventHappened?(value)
@ -184,10 +177,6 @@ final class ExtendCollectionViewDelegateProxy
final class UICollectionViewSubclass1
: UICollectionView
, TestDelegateControl {
override func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
return ExtendCollectionViewDelegateProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
(delegate as! TestDelegateProtocol).testEventHappened?(value)
}
@ -215,9 +204,6 @@ final class ExtendCollectionViewDataSourceProxy
final class UICollectionViewSubclass2
: UICollectionView
, TestDelegateControl {
override func createRxDataSourceProxy() -> RxCollectionViewDataSourceProxy {
return ExtendCollectionViewDataSourceProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
if dataSource != nil {
@ -248,10 +234,6 @@ final class ExtendScrollViewDelegateProxy
final class UIScrollViewSubclass
: UIScrollView
, TestDelegateControl {
override func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
return ExtendScrollViewDelegateProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
(delegate as! TestDelegateProtocol).testEventHappened?(value)
}
@ -280,11 +262,6 @@ final class ExtendSearchBarDelegateProxy
final class UISearchBarSubclass
: UISearchBar
, TestDelegateControl {
override func createRxDelegateProxy() -> RxSearchBarDelegateProxy {
return ExtendSearchBarDelegateProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
(delegate as! TestDelegateProtocol).testEventHappened?(value)
}
@ -313,10 +290,6 @@ final class ExtendTextViewDelegateProxy
final class UITextViewSubclass
: UITextView
, TestDelegateControl {
override func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
return ExtendTextViewDelegateProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
(delegate as! TestDelegateProtocol).testEventHappened?(value)
}
@ -341,11 +314,6 @@ final class ExtendSearchControllerDelegateProxy
final class UISearchControllerSubclass
: UISearchController
, TestDelegateControl {
override func createRxDelegateProxy() -> RxSearchControllerDelegateProxy {
return ExtendSearchControllerDelegateProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
(delegate as! TestDelegateProtocol).testEventHappened?(value)
}
@ -371,11 +339,6 @@ final class ExtendPickerViewDelegateProxy
final class UIPickerViewSubclass
: UIPickerView
, TestDelegateControl {
public override func createRxDelegateProxy() -> RxPickerViewDelegateProxy {
return ExtendPickerViewDelegateProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
(delegate as! TestDelegateProtocol).testEventHappened?(value)
}
@ -400,11 +363,6 @@ final class ExtendWebViewDelegateProxy
}
final class UIWebViewSubclass: UIWebView, TestDelegateControl {
override func createRxDelegateProxy() -> RxWebViewDelegateProxy {
return ExtendWebViewDelegateProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
(delegate as! TestDelegateProtocol).testEventHappened?(value)
}
@ -437,11 +395,6 @@ final class ExtendTextStorageDelegateProxy
final class NSTextStorageSubclass
: NSTextStorage
, TestDelegateControl {
override func createRxDelegateProxy() -> RxTextStorageDelegateProxy {
return ExtendTextStorageDelegateProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
(delegate as! TestDelegateProtocol).testEventHappened?(value)
}
@ -489,10 +442,6 @@ final class ExtendTabBarDelegateProxy
}
final class UINavigationControllerSubclass: UINavigationController, TestDelegateControl {
override func createRxDelegateProxy() -> RxNavigationControllerDelegateProxy {
return ExtendNavigationControllerDelegateProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
(delegate as! TestDelegateProtocol).testEventHappened?(value)
}
@ -511,10 +460,6 @@ final class UINavigationControllerSubclass: UINavigationController, TestDelegate
final class UITabBarControllerSubclass
: UITabBarController
, TestDelegateControl {
override func createRxDelegateProxy() -> RxTabBarControllerDelegateProxy {
return ExtendTabBarControllerDelegateProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
(delegate as! TestDelegateProtocol).testEventHappened?(value)
}
@ -529,10 +474,6 @@ final class UITabBarControllerSubclass
}
final class UITabBarSubclass: UITabBar, TestDelegateControl {
override func createRxDelegateProxy() -> RxTabBarDelegateProxy {
return ExtendTabBarDelegateProxy(parentObject: self)
}
func doThatTest(_ value: Int) {
(delegate as! TestDelegateProtocol).testEventHappened?(value)
}

View File

@ -56,6 +56,62 @@ extension TestDelegateControl {
// MARK: Tests
final class DelegateProxyTest : RxTest {
override func setUp() {
super.setUp()
// setup extending of DelegateProxies
#if os(iOS) || os(tvOS)
RxScrollViewDelegateProxy.extend { (parentObject: UIScrollViewSubclass) in
ExtendScrollViewDelegateProxy(parentObject: parentObject)
}
RxScrollViewDelegateProxy.extend { (parentObject: UITableViewSubclass1) in
ExtendTableViewDelegateProxy(parentObject: parentObject)
}
RxTableViewDataSourceProxy.extend { (parentObject: UITableViewSubclass2) in
ExtendTableViewDataSourceProxy(parentObject: parentObject)
}
RxScrollViewDelegateProxy.extend { (parentObject: UICollectionViewSubclass1) in
ExtendCollectionViewDelegateProxy(parentObject: parentObject)
}
RxCollectionViewDataSourceProxy.extend { (parentObject: UICollectionViewSubclass2) in
ExtendCollectionViewDataSourceProxy(parentObject: parentObject)
}
RxScrollViewDelegateProxy.extend { (parentObject: UITextViewSubclass) in
ExtendTextViewDelegateProxy(parentObject: parentObject)
}
RxTextStorageDelegateProxy.extend { (parentObject: NSTextStorageSubclass) in
ExtendTextStorageDelegateProxy(parentObject: parentObject)
}
RxNavigationControllerDelegateProxy.extend { (parentObject: UINavigationControllerSubclass) in
ExtendNavigationControllerDelegateProxy(parentObject: parentObject)
}
RxTabBarControllerDelegateProxy.extend { (parentObject: UITabBarControllerSubclass) in
ExtendTabBarControllerDelegateProxy(parentObject: parentObject)
}
RxTabBarDelegateProxy.extend { (parentObject: UITabBarSubclass) -> AnyObject in
ExtendTabBarDelegateProxy(parentObject: parentObject)
}
#endif
#if os(iOS)
RxSearchBarDelegateProxy.extend { (parentObject: UISearchBarSubclass) in
ExtendSearchBarDelegateProxy(parentObject: parentObject)
}
RxSearchControllerDelegateProxy.extend { (parentObject: UISearchControllerSubclass) in
ExtendSearchControllerDelegateProxy(parentObject: parentObject)
}
RxPickerViewDelegateProxy.extend { (parentObject: UIPickerViewSubclass) in
ExtendPickerViewDelegateProxy(parentObject: parentObject)
}
RxWebViewDelegateProxy.extend { (parentObject: UIWebViewSubclass) in
ExtendWebViewDelegateProxy(parentObject: parentObject)
}
#endif
#if os(macOS)
RxTextFieldDelegateProxy.extend { (parentObject: NSTextFieldSubclass) in
ExtendNSTextFieldDelegateProxy(parentObject: parentObject)
}
#endif
}
func test_OnInstallDelegateIsRetained() {
let view = ThreeDSectionedView()
let mock = MockThreeDSectionedViewProtocol()
@ -419,6 +475,11 @@ final class ThreeDSectionedView: NSObject {
final class ThreeDSectionedViewDelegateProxy : DelegateProxy
, ThreeDSectionedViewProtocol
, DelegateProxyType {
static var factories: [((AnyObject) -> AnyObject?)] = [
{ ThreeDSectionedViewDelegateProxy(parentObject: $0) }
]
required init(parentObject: AnyObject) {
super.init(parentObject: parentObject)
}