mirror of
https://github.com/ReactiveX/RxSwift.git
synced 2024-10-04 14:07:22 +03:00
Simplifies DelegateProxy.
This commit is contained in:
parent
f61ecc7b5f
commit
d1bc89b5ef
@ -1439,10 +1439,6 @@
|
||||
D2138C881BB9BEBE00339B5C /* DelegateProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8093E8B1B8A732E0088E94D /* DelegateProxy.swift */; };
|
||||
D2138C891BB9BEBE00339B5C /* DelegateProxyType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8093E8C1B8A732E0088E94D /* DelegateProxyType.swift */; };
|
||||
D2138C991BB9BEEE00339B5C /* RxTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8093E9C1B8A732E0088E94D /* RxTarget.swift */; };
|
||||
D29E23191EF4B93D006E295D /* DelegateProxyFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = D29E23171EF4B92E006E295D /* DelegateProxyFactory.swift */; };
|
||||
D29E231A1EF4B93E006E295D /* DelegateProxyFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = D29E23171EF4B92E006E295D /* DelegateProxyFactory.swift */; };
|
||||
D29E231B1EF4B93E006E295D /* DelegateProxyFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = D29E23171EF4B92E006E295D /* DelegateProxyFactory.swift */; };
|
||||
D29E231C1EF4B93F006E295D /* DelegateProxyFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = D29E23171EF4B92E006E295D /* DelegateProxyFactory.swift */; };
|
||||
D2EBEADC1BB9B697003A27DC /* Cancelable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8093C491B8A72BE0088E94D /* Cancelable.swift */; };
|
||||
D2EBEADD1BB9B697003A27DC /* ConnectableObservableType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8093C4D1B8A72BE0088E94D /* ConnectableObservableType.swift */; };
|
||||
D2EBEADE1BB9B697003A27DC /* Disposable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8093C521B8A72BE0088E94D /* Disposable.swift */; };
|
||||
@ -2198,7 +2194,6 @@
|
||||
CB883B441BE256D4000AC2EE /* BooleanDisposable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BooleanDisposable.swift; sourceTree = "<group>"; };
|
||||
CDDEF1691D4FB40000CA8546 /* Disposables.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Disposables.swift; sourceTree = "<group>"; };
|
||||
D2138C751BB9BE9800339B5C /* RxCocoa.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxCocoa.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
D29E23171EF4B92E006E295D /* DelegateProxyFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DelegateProxyFactory.swift; sourceTree = "<group>"; };
|
||||
D2EA280C1BB9B5A200880ED3 /* RxSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
D2EBEB811BB9B99D003A27DC /* RxBlocking.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxBlocking.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
D9080ACD1EA05A16002B433B /* RxNavigationControllerDelegateProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxNavigationControllerDelegateProxy.swift; sourceTree = "<group>"; };
|
||||
@ -2585,7 +2580,6 @@
|
||||
C80D338E1B91EF9E0014629D /* Observable+Bind.swift */,
|
||||
C8093E8B1B8A732E0088E94D /* DelegateProxy.swift */,
|
||||
C8093E8C1B8A732E0088E94D /* DelegateProxyType.swift */,
|
||||
D29E23171EF4B92E006E295D /* DelegateProxyFactory.swift */,
|
||||
C8093E9C1B8A732E0088E94D /* RxTarget.swift */,
|
||||
C89AB1711DAAC1680065FBE6 /* ControlTarget.swift */,
|
||||
C8BCD3F31C14B6D1005F1280 /* NSLayoutConstraint+Rx.swift */,
|
||||
@ -4141,7 +4135,6 @@
|
||||
C882542B1B8A752B00B02D69 /* UIDatePicker+Rx.swift in Sources */,
|
||||
C88254221B8A752B00B02D69 /* RxTableViewDataSourceProxy.swift in Sources */,
|
||||
C8BCD3F41C14B6D1005F1280 /* NSLayoutConstraint+Rx.swift in Sources */,
|
||||
D29E23191EF4B93D006E295D /* DelegateProxyFactory.swift in Sources */,
|
||||
C882542C1B8A752B00B02D69 /* UIGestureRecognizer+Rx.swift in Sources */,
|
||||
C89AB1D21DAAC3350065FBE6 /* ControlProperty+Driver.swift in Sources */,
|
||||
C8093EE11B8A732E0088E94D /* DelegateProxy.swift in Sources */,
|
||||
@ -4216,7 +4209,6 @@
|
||||
C8B0F71A1F530FE400548EBE /* PublishRelay.swift in Sources */,
|
||||
C86781A61DB823B500B2029A /* NSSlider+Rx.swift in Sources */,
|
||||
C89AB2231DAAC3350065FBE6 /* URLSession+Rx.swift in Sources */,
|
||||
D29E231A1EF4B93E006E295D /* DelegateProxyFactory.swift in Sources */,
|
||||
C86781A11DB823B500B2029A /* NSImageView+Rx.swift in Sources */,
|
||||
C89AB2281DAAC33F0065FBE6 /* RxCocoa.swift in Sources */,
|
||||
C8D132451C42D15E00B59FFF /* SectionedViewDataSourceType.swift in Sources */,
|
||||
@ -5367,7 +5359,6 @@
|
||||
C8F0C03B1BBBFBB9001B112F /* UISearchBar+Rx.swift in Sources */,
|
||||
C89AB2431DAAC3A60065FBE6 /* _RXDelegateProxy.m in Sources */,
|
||||
C8F0C03C1BBBFBB9001B112F /* ItemEvents.swift in Sources */,
|
||||
D29E231C1EF4B93F006E295D /* DelegateProxyFactory.swift in Sources */,
|
||||
7EDBAEBF1C89B9B7006CBE67 /* UITabBarItem+Rx.swift in Sources */,
|
||||
C8F0C03D1BBBFBB9001B112F /* RxTableViewDataSourceType.swift in Sources */,
|
||||
);
|
||||
@ -5431,7 +5422,6 @@
|
||||
C89AB1751DAAC1680065FBE6 /* ControlTarget.swift in Sources */,
|
||||
D203C4FB1BB9C53700D02D00 /* RxCollectionViewDelegateProxy.swift in Sources */,
|
||||
D203C5031BB9C53E00D02D00 /* UIBarButtonItem+Rx.swift in Sources */,
|
||||
D29E231B1EF4B93E006E295D /* DelegateProxyFactory.swift in Sources */,
|
||||
C89AB1EC1DAAC3350065FBE6 /* SharedSequence+Operators+arity.swift in Sources */,
|
||||
C85E6FC01F53025700C5681E /* SchedulerType+SharedSequence.swift in Sources */,
|
||||
D203C4FC1BB9C53700D02D00 /* RxScrollViewDelegateProxy.swift in Sources */,
|
||||
|
@ -15,9 +15,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
let delegateAssociatedTag: UnsafeRawPointer = UnsafeRawPointer(UnsafeMutablePointer<UInt8>.allocate(capacity: 1))
|
||||
let dataSourceAssociatedTag: UnsafeRawPointer = UnsafeRawPointer(UnsafeMutablePointer<UInt8>.allocate(capacity: 1))
|
||||
|
||||
/// Base class for `DelegateProxyType` protocol.
|
||||
///
|
||||
/// This implementation is not thread safe and can be used only from one thread (Main thread).
|
||||
@ -34,7 +31,7 @@ open class DelegateProxy<P: AnyObject, D: NSObjectProtocol>: _RXDelegateProxy {
|
||||
/// Initializes new instance.
|
||||
///
|
||||
/// - parameter parentObject: Optional parent object that owns `DelegateProxy` as associated object.
|
||||
public required init(parentObject: ParentObject) {
|
||||
public init(parentObject: ParentObject) {
|
||||
self.parentObject = parentObject
|
||||
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
@ -183,31 +180,6 @@ open class DelegateProxy<P: AnyObject, D: NSObjectProtocol>: _RXDelegateProxy {
|
||||
methodInvokedForSelector[selector]?.on(.next(arguments))
|
||||
}
|
||||
|
||||
/// Returns tag used to identify associated object.
|
||||
///
|
||||
/// - returns: Associated object tag.
|
||||
open class func delegateAssociatedObjectTag() -> UnsafeRawPointer {
|
||||
return delegateAssociatedTag
|
||||
}
|
||||
|
||||
/// Returns assigned proxy for object.
|
||||
///
|
||||
/// - parameter object: Object that can have assigned delegate proxy.
|
||||
/// - returns: Assigned delegate proxy or `nil` if no delegate proxy is assigned.
|
||||
open class func assignedProxy(for object: ParentObject) -> Delegate? {
|
||||
let maybeDelegate = objc_getAssociatedObject(object, self.delegateAssociatedObjectTag())
|
||||
return castOptionalOrFatalError(maybeDelegate.map { $0 as AnyObject })
|
||||
}
|
||||
|
||||
/// Assigns proxy to object.
|
||||
///
|
||||
/// - parameter object: Object that can have assigned delegate proxy.
|
||||
/// - parameter proxy: Delegate proxy object to assign to `object`.
|
||||
open class func assignProxy(_ proxy: Delegate, toObject object: ParentObject) {
|
||||
objc_setAssociatedObject(object, self.delegateAssociatedObjectTag(), proxy, .OBJC_ASSOCIATION_RETAIN)
|
||||
}
|
||||
|
||||
|
||||
/// Returns designated delegate property for object.
|
||||
///
|
||||
/// Objects can have multiple delegate properties.
|
||||
|
@ -1,100 +0,0 @@
|
||||
//
|
||||
// DelegateProxyFactory.swift
|
||||
// RxCocoa
|
||||
//
|
||||
// Created by tarunon on 2017/06/17.
|
||||
// Copyright © 2017 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
#if !os(Linux)
|
||||
|
||||
#if !RX_NO_MODULE
|
||||
import RxSwift
|
||||
#endif
|
||||
|
||||
/**
|
||||
Define `DelegateProxy.init` for a specific object type.
|
||||
For example, in RxScrollViewDelegateProxy
|
||||
|
||||
|
||||
class RxScrollViewDelegateProxy: DelegateProxy {
|
||||
static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxScrollViewDelegateProxy.self)
|
||||
}
|
||||
...
|
||||
|
||||
|
||||
If need to extend them, call `DelegateProxySubclass.register()` in `knownImplementations`.
|
||||
|
||||
class RxScrollViewDelegateProxy: DelegateProxy {
|
||||
static func knownImplementations() {
|
||||
RxTableViewDelegateProxy.register(for: UITableView)
|
||||
}
|
||||
|
||||
static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxScrollViewDelegateProxy.self)
|
||||
}
|
||||
...
|
||||
|
||||
|
||||
*/
|
||||
public class DelegateProxyFactory {
|
||||
private static var _sharedFactories: [ObjectIdentifier: DelegateProxyFactory] = [:]
|
||||
|
||||
/**
|
||||
Shared instance of DelegateProxyFactory, if isn't exist shared instance, make DelegateProxyFactory instance for proxy type and extends.
|
||||
DelegateProxyFactory have a shared instance per Delegate type.
|
||||
- parameter proxyType: DelegateProxy type. Should use concrete DelegateProxy type, not generic.
|
||||
- returns: DelegateProxyFactory shared instance.
|
||||
*/
|
||||
public static func sharedFactory<DelegateProxy: DelegateProxyType>(for proxyType: DelegateProxy.Type) -> DelegateProxyFactory {
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
if let factory = _sharedFactories[ObjectIdentifier(DelegateProxy.Delegate.self)] {
|
||||
return factory
|
||||
}
|
||||
let factory = DelegateProxyFactory(for: proxyType)
|
||||
_sharedFactories[ObjectIdentifier(DelegateProxy.Delegate.self)] = factory
|
||||
DelegateProxy.knownImplementations()
|
||||
return factory
|
||||
}
|
||||
|
||||
private var _factories: [ObjectIdentifier: ((AnyObject) -> AnyObject)]
|
||||
|
||||
private init<DelegateProxy: DelegateProxyType>(for proxyType: DelegateProxy.Type) {
|
||||
_factories = [:]
|
||||
self.extend(with: proxyType, for: DelegateProxy.ParentObject.self)
|
||||
}
|
||||
|
||||
/**
|
||||
Extend DelegateProxyFactory for specific object class and delegate proxy.
|
||||
- parameter proxyType: The DelegateProxy type that subclass of factorys owner.
|
||||
- parameter parentObjectType: Parent object type of DelegateProxy.
|
||||
*/
|
||||
internal func extend<DelegateProxy: DelegateProxyType>(with proxyType: DelegateProxy.Type, for parentObjectType: DelegateProxy.ParentObject.Type) {
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
assert((DelegateProxy.self as? DelegateProxy.Delegate) != nil, "DelegateProxy subclass should be as a Delegate")
|
||||
guard _factories[ObjectIdentifier(parentObjectType)] == nil else {
|
||||
rxFatalError("The factory of \(parentObjectType) is duplicated. DelegateProxy is not allowed of duplicated base object type.")
|
||||
}
|
||||
_factories[ObjectIdentifier(parentObjectType)] = { proxyType.init(parentObject: castOrFatalError($0)) }
|
||||
}
|
||||
|
||||
/**
|
||||
Create DelegateProxy for object.
|
||||
DelegateProxyFactory should have a factory of object class (or superclass).
|
||||
Should not call this function directory, use 'DelegateProxy.proxy(for:)'
|
||||
*/
|
||||
internal func createProxy(for object: AnyObject) -> AnyObject {
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
var mirror: Mirror? = Mirror(reflecting: object)
|
||||
while mirror != nil {
|
||||
if let factory = _factories[ObjectIdentifier(mirror!.subjectType)] {
|
||||
return factory(object)
|
||||
}
|
||||
mirror = mirror?.superclassMirror
|
||||
}
|
||||
rxFatalError("DelegateProxy has no factory of \(object). Implement DelegateProxy subclass for \(object) first.")
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -55,63 +55,29 @@ This is more or less how it works.
|
||||
+-------------------------------------------+
|
||||
|
||||
|
||||
Since RxCocoa needs to automagically create those Proxys
|
||||
..and because views that have delegates can be hierarchical
|
||||
Since RxCocoa needs to automagically create those Proxys and because views that have delegates can be hierarchical
|
||||
|
||||
UITableView : UIScrollView : UIView
|
||||
UITableView : UIScrollView : UIView
|
||||
|
||||
.. and corresponding delegates are also hierarchical
|
||||
|
||||
UITableViewDelegate : UIScrollViewDelegate : NSObject
|
||||
UITableViewDelegate : UIScrollViewDelegate : NSObject
|
||||
|
||||
.. and sometimes there can be only one proxy/delegate registered,
|
||||
every view has a corresponding delegate virtual factory method.
|
||||
|
||||
In case of UITableView / UIScrollView, there is
|
||||
|
||||
class RxScrollViewDelegateProxy: DelegateProxy {
|
||||
static var factory = DelegateProxyFactory { (parentObject: UIScrollView) in
|
||||
RxScrollViewDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
}
|
||||
....
|
||||
|
||||
|
||||
and extend it
|
||||
|
||||
RxScrollViewDelegateProxy.extendProxy { (parentObject: UITableView) in
|
||||
RxTableViewDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
... this mechanism can be extended by using the following snippet in `registerKnownImplementations` or in some other
|
||||
part of your app that executes before using `rx.*` (e.g. appDidFinishLaunching).
|
||||
|
||||
RxScrollViewDelegateProxy.register { RxTableViewDelegateProxy(parentObject: $0) }
|
||||
|
||||
*/
|
||||
public protocol DelegateProxyType : AnyObject {
|
||||
associatedtype ParentObject: AnyObject
|
||||
associatedtype Delegate: AnyObject
|
||||
|
||||
/// DelegateProxy factory. Use 'DelegateProxyFactory.sharedFactory'.
|
||||
static var factory: DelegateProxyFactory { get }
|
||||
|
||||
/// Creates new proxy for target object.
|
||||
/// Should not call this function directory, use 'DelegateProxy.proxy(for:)'
|
||||
static func createProxy(for object: AnyObject) -> AnyObject
|
||||
|
||||
/// It is require that enumerate call `register` of the extended DelegateProxy subclasses here.
|
||||
static func knownImplementations()
|
||||
static func registerKnownImplementations()
|
||||
|
||||
init(parentObject: ParentObject)
|
||||
|
||||
/// Returns assigned proxy for object.
|
||||
///
|
||||
/// - parameter object: Object that can have assigned delegate proxy.
|
||||
/// - returns: Assigned delegate proxy or `nil` if no delegate proxy is assigned.
|
||||
static func assignedProxy(for object: ParentObject) -> Delegate?
|
||||
|
||||
/// Assigns proxy to object.
|
||||
///
|
||||
/// - parameter object: Object that can have assigned delegate proxy.
|
||||
/// - parameter proxy: Delegate proxy object to assign to `object`.
|
||||
static func assignProxy(_ proxy: Delegate, toObject object: ParentObject)
|
||||
/// Unique identifier for delegate
|
||||
static var identifier: UnsafeRawPointer { get }
|
||||
|
||||
/// Returns designated delegate property for object.
|
||||
///
|
||||
@ -151,26 +117,30 @@ public protocol DelegateProxyType : AnyObject {
|
||||
func setForwardToDelegate(_ forwardToDelegate: Delegate?, retainDelegate: Bool)
|
||||
}
|
||||
|
||||
// default implementations
|
||||
extension DelegateProxyType {
|
||||
/// Unique identifier for delegate
|
||||
public static var identifier: UnsafeRawPointer {
|
||||
let delegateIdentifier = ObjectIdentifier(Delegate.self)
|
||||
let integerIdentifier = Int(bitPattern: delegateIdentifier)
|
||||
return UnsafeRawPointer(bitPattern: integerIdentifier)!
|
||||
}
|
||||
}
|
||||
|
||||
extension DelegateProxyType {
|
||||
|
||||
/// Store DelegateProxy subclass to factory.
|
||||
/// When make 'Rx*DelegateProxy' subclass, call 'Rx*DelegateProxySubclass.register(for:_)' 1 time, or use it in DelegateProxyFactory
|
||||
/// 'Rx*DelegateProxy' can have one subclass implementation per concrete ParentObject type.
|
||||
/// Should call it from concrete DelegateProxy type, not generic.
|
||||
public static func register(for parentObjectType: ParentObject.Type) {
|
||||
self.factory.extend(with: self, for: parentObjectType)
|
||||
public static func register<Parent>(make: @escaping (Parent) -> Self) {
|
||||
self.factory.extend(make: make)
|
||||
}
|
||||
|
||||
/// It is require that enumerate call `register` of the extended DelegateProxy subclasses here.
|
||||
/// Default is nop
|
||||
public static func knownImplementations() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Creates new proxy for target object.
|
||||
/// Should not call this function directory, use 'DelegateProxy.proxy(for:)'
|
||||
public static func createProxy(for object: AnyObject) -> AnyObject {
|
||||
return factory.createProxy(for: object)
|
||||
public static func createProxy(for object: AnyObject) -> Self {
|
||||
return castOrFatalError(factory.createProxy(for: object))
|
||||
}
|
||||
|
||||
/// Returns existing proxy for object or installs new instance of delegate proxy.
|
||||
@ -250,6 +220,24 @@ extension DelegateProxyType {
|
||||
}
|
||||
}
|
||||
|
||||
// fileprivate extensions
|
||||
extension DelegateProxyType
|
||||
{
|
||||
fileprivate static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: self)
|
||||
}
|
||||
|
||||
|
||||
fileprivate static func assignedProxy(for object: ParentObject) -> Delegate? {
|
||||
let maybeDelegate = objc_getAssociatedObject(object, self.identifier)
|
||||
return castOptionalOrFatalError(maybeDelegate.map { $0 as AnyObject })
|
||||
}
|
||||
|
||||
fileprivate static func assignProxy(_ proxy: Delegate, toObject object: ParentObject) {
|
||||
objc_setAssociatedObject(object, self.identifier, proxy, .OBJC_ASSOCIATION_RETAIN)
|
||||
}
|
||||
}
|
||||
|
||||
#if os(iOS) || os(tvOS)
|
||||
import UIKit
|
||||
|
||||
@ -300,4 +288,66 @@ extension DelegateProxyType {
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
To add delegate proxy subclasses call `DelegateProxySubclass.register()` in `registerKnownImplementations` or in some other
|
||||
part of your app that executes before using `rx.*` (e.g. appDidFinishLaunching).
|
||||
|
||||
class RxScrollViewDelegateProxy: DelegateProxy {
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxTableViewDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
...
|
||||
|
||||
|
||||
*/
|
||||
private class DelegateProxyFactory {
|
||||
private static var _sharedFactories: [UnsafeRawPointer: DelegateProxyFactory] = [:]
|
||||
|
||||
fileprivate static func sharedFactory<DelegateProxy: DelegateProxyType>(for proxyType: DelegateProxy.Type) -> DelegateProxyFactory {
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
let identifier = DelegateProxy.identifier
|
||||
if let factory = _sharedFactories[identifier] {
|
||||
return factory
|
||||
}
|
||||
let factory = DelegateProxyFactory(for: proxyType)
|
||||
_sharedFactories[identifier] = factory
|
||||
DelegateProxy.registerKnownImplementations()
|
||||
return factory
|
||||
}
|
||||
|
||||
private var _factories: [ObjectIdentifier: ((AnyObject) -> AnyObject)]
|
||||
private var _delegateProxyType: Any.Type
|
||||
private var _identifier: UnsafeRawPointer
|
||||
|
||||
private init<DelegateProxy: DelegateProxyType>(for proxyType: DelegateProxy.Type) {
|
||||
_factories = [:]
|
||||
_delegateProxyType = proxyType
|
||||
_identifier = proxyType.identifier
|
||||
}
|
||||
|
||||
fileprivate func extend<DelegateProxy: DelegateProxyType, ParentObject>(make: @escaping (ParentObject) -> DelegateProxy)
|
||||
{
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
precondition(_identifier == DelegateProxy.identifier, "Delegate proxy has inconsistent identifier")
|
||||
precondition((DelegateProxy.self as? DelegateProxy.Delegate) != nil, "DelegateProxy subclass should be as a Delegate")
|
||||
guard _factories[ObjectIdentifier(ParentObject.self)] == nil else {
|
||||
rxFatalError("The factory of \(ParentObject.self) is duplicated. DelegateProxy is not allowed of duplicated base object type.")
|
||||
}
|
||||
_factories[ObjectIdentifier(ParentObject.self)] = { make(castOrFatalError($0)) }
|
||||
}
|
||||
|
||||
fileprivate func createProxy(for object: AnyObject) -> AnyObject {
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
var maybeMirror: Mirror? = Mirror(reflecting: object)
|
||||
while let mirror = maybeMirror {
|
||||
if let factory = _factories[ObjectIdentifier(mirror.subjectType)] {
|
||||
return factory(object)
|
||||
}
|
||||
maybeMirror = mirror.superclassMirror
|
||||
}
|
||||
rxFatalError("DelegateProxy has no factory of \(object). Implement DelegateProxy subclass for \(object) first.")
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -37,8 +37,9 @@ open class RxCollectionViewDataSourceProxy
|
||||
, DelegateProxyType
|
||||
, UICollectionViewDataSource {
|
||||
|
||||
public static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxCollectionViewDataSourceProxy.self)
|
||||
// Register known implementations
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxCollectionViewDataSourceProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
/// Typed parent object.
|
||||
@ -49,7 +50,7 @@ open class RxCollectionViewDataSourceProxy
|
||||
/// Initializes `RxCollectionViewDataSourceProxy`
|
||||
///
|
||||
/// - parameter parentObject: Parent object for delegate proxy.
|
||||
public required init(parentObject: ParentObject) {
|
||||
public override init(parentObject: ParentObject) {
|
||||
self.collectionView = parentObject
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
@ -68,11 +69,6 @@ open class RxCollectionViewDataSourceProxy
|
||||
|
||||
// MARK: proxy
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
open override class func delegateAssociatedObjectTag() -> UnsafeRawPointer {
|
||||
return dataSourceAssociatedTag
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
open override class func setCurrentDelegate(_ delegate: UICollectionViewDataSource?, toObject object: ParentObject) {
|
||||
object.dataSource = delegate
|
||||
|
@ -25,8 +25,8 @@ open class RxCollectionViewDelegateProxy
|
||||
/// Initializes `RxCollectionViewDelegateProxy`
|
||||
///
|
||||
/// - parameter parentObject: Parent object for delegate proxy.
|
||||
public required init(parentObject: ParentObject) {
|
||||
self.collectionView = castOrFatalError(parentObject)
|
||||
public init(parentObject: UICollectionView) {
|
||||
self.collectionView = parentObject
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,9 @@
|
||||
, DelegateProxyType
|
||||
, UINavigationControllerDelegate {
|
||||
|
||||
public static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxNavigationControllerDelegateProxy.self)
|
||||
// Register known implementations
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxNavigationControllerDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
|
@ -31,8 +31,9 @@ public class RxPickerViewDataSourceProxy
|
||||
, DelegateProxyType
|
||||
, UIPickerViewDataSource {
|
||||
|
||||
public static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxPickerViewDataSourceProxy.self)
|
||||
// Register known implementations
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxPickerViewDataSourceProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
/// Typed parent object.
|
||||
@ -42,7 +43,7 @@ public class RxPickerViewDataSourceProxy
|
||||
/// Initializes `RxPickerViewDataSourceProxy`
|
||||
///
|
||||
/// - parameter parentObject: Parent object for delegate proxy.
|
||||
public required init(parentObject: UIPickerView) {
|
||||
public override init(parentObject: ParentObject) {
|
||||
self.pickerView = parentObject
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
@ -61,11 +62,6 @@ public class RxPickerViewDataSourceProxy
|
||||
|
||||
// MARK: proxy
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func delegateAssociatedObjectTag() -> UnsafeRawPointer {
|
||||
return dataSourceAssociatedTag
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func setCurrentDelegate(_ delegate: UIPickerViewDataSource?, toObject object: UIPickerView) {
|
||||
object.dataSource = delegate
|
||||
|
@ -18,8 +18,9 @@
|
||||
, DelegateProxyType
|
||||
, UIPickerViewDelegate {
|
||||
|
||||
public static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxPickerViewDelegateProxy.self)
|
||||
// Register known implementationss
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxPickerViewDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
|
@ -18,15 +18,13 @@ open class RxScrollViewDelegateProxy
|
||||
: DelegateProxy<UIScrollView, UIScrollViewDelegate>
|
||||
, DelegateProxyType
|
||||
, UIScrollViewDelegate {
|
||||
|
||||
public static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxScrollViewDelegateProxy.self)
|
||||
}
|
||||
|
||||
public static func knownImplementations() {
|
||||
RxTableViewDelegateProxy.register(for: UITableView.self)
|
||||
RxCollectionViewDelegateProxy.register(for: UICollectionView.self)
|
||||
RxTextViewDelegateProxy.register(for: UITextView.self)
|
||||
|
||||
// Register known implementations
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxScrollViewDelegateProxy(parentObject: $0) }
|
||||
self.register { RxTableViewDelegateProxy(parentObject: $0) }
|
||||
self.register { RxCollectionViewDelegateProxy(parentObject: $0) }
|
||||
self.register { RxTextViewDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
fileprivate var _contentOffsetBehaviorSubject: BehaviorSubject<CGPoint>?
|
||||
@ -62,7 +60,7 @@ open class RxScrollViewDelegateProxy
|
||||
/// Initializes `RxScrollViewDelegateProxy`
|
||||
///
|
||||
/// - parameter parentObject: Parent object for delegate proxy.
|
||||
public required init(parentObject: ParentObject) {
|
||||
public override init(parentObject: ParentObject) {
|
||||
self.scrollView = parentObject
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
|
@ -19,11 +19,12 @@ open class RxSearchBarDelegateProxy
|
||||
, DelegateProxyType
|
||||
, UISearchBarDelegate {
|
||||
|
||||
// MARK: Delegate proxy methods
|
||||
|
||||
public static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxSearchBarDelegateProxy.self)
|
||||
// Register known implementations
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxSearchBarDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
// MARK: Delegate proxy methods
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
open override class func currentDelegate(for object: ParentObject) -> UISearchBarDelegate? {
|
||||
|
@ -20,10 +20,11 @@ open class RxSearchControllerDelegateProxy
|
||||
, DelegateProxyType
|
||||
, UISearchControllerDelegate {
|
||||
|
||||
public static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxSearchControllerDelegateProxy.self)
|
||||
// Register known implementations
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxSearchControllerDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
open override class func setCurrentDelegate(_ delegate: UISearchControllerDelegate?, toObject object: ParentObject) {
|
||||
object.delegate = delegate
|
||||
|
@ -19,8 +19,9 @@ open class RxTabBarControllerDelegateProxy
|
||||
, DelegateProxyType
|
||||
, UITabBarControllerDelegate {
|
||||
|
||||
public static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxTabBarControllerDelegateProxy.self)
|
||||
// Register known implementations
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxTabBarControllerDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
|
@ -19,8 +19,9 @@ open class RxTabBarDelegateProxy
|
||||
, DelegateProxyType
|
||||
, UITabBarDelegate {
|
||||
|
||||
public static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxTabBarDelegateProxy.self)
|
||||
// Register known implementations
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxTabBarDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
|
@ -34,8 +34,9 @@ open class RxTableViewDataSourceProxy
|
||||
, DelegateProxyType
|
||||
, UITableViewDataSource {
|
||||
|
||||
public static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxTableViewDataSourceProxy.self)
|
||||
// Register known implementations
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxTableViewDataSourceProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
/// Typed parent object.
|
||||
@ -46,7 +47,7 @@ open class RxTableViewDataSourceProxy
|
||||
/// Initializes `RxTableViewDataSourceProxy`
|
||||
///
|
||||
/// - parameter parentObject: Parent object for delegate proxy.
|
||||
public required init(parentObject: ParentObject) {
|
||||
public override init(parentObject: UITableView) {
|
||||
self.tableView = parentObject
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
@ -65,11 +66,6 @@ open class RxTableViewDataSourceProxy
|
||||
|
||||
// MARK: proxy
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
open override class func delegateAssociatedObjectTag() -> UnsafeRawPointer {
|
||||
return dataSourceAssociatedTag
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
open override class func setCurrentDelegate(_ delegate: UITableViewDataSource?, toObject object: ParentObject) {
|
||||
object.dataSource = delegate
|
||||
|
@ -18,15 +18,14 @@ open class RxTableViewDelegateProxy
|
||||
: RxScrollViewDelegateProxy
|
||||
, UITableViewDelegate {
|
||||
|
||||
|
||||
/// Typed parent object.
|
||||
public weak private(set) var tableView: UITableView?
|
||||
|
||||
/// Initializes `RxTableViewDelegateProxy`
|
||||
///
|
||||
/// - parameter parentObject: Parent object for delegate proxy.
|
||||
public required init(parentObject: ParentObject) {
|
||||
self.tableView = castOrFatalError(parentObject)
|
||||
public init(parentObject: UITableView) {
|
||||
self.tableView = parentObject
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
|
||||
|
@ -17,10 +17,12 @@
|
||||
: DelegateProxy<NSTextStorage, NSTextStorageDelegate>
|
||||
, DelegateProxyType
|
||||
, NSTextStorageDelegate {
|
||||
public static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxTextStorageDelegateProxy.self)
|
||||
|
||||
// Register known implementations
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxTextStorageDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
open override class func setCurrentDelegate(_ delegate: NSTextStorageDelegate?, toObject object: ParentObject) {
|
||||
object.delegate = delegate
|
||||
|
@ -24,7 +24,7 @@ open class RxTextViewDelegateProxy
|
||||
/// Initializes `RxTextViewDelegateProxy`
|
||||
///
|
||||
/// - parameter parentObject: Parent object for delegate proxy.
|
||||
public required init(parentObject: ParentObject) {
|
||||
public init(parentObject: UITextView) {
|
||||
self.textView = castOrFatalError(parentObject)
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
|
@ -18,8 +18,9 @@ open class RxWebViewDelegateProxy
|
||||
, DelegateProxyType
|
||||
, UIWebViewDelegate {
|
||||
|
||||
public static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxWebViewDelegateProxy.self)
|
||||
// Register known implementations
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxWebViewDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
|
@ -21,10 +21,6 @@ open class RxTextFieldDelegateProxy
|
||||
, DelegateProxyType
|
||||
, NSTextFieldDelegate {
|
||||
|
||||
public static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxTextFieldDelegateProxy.self)
|
||||
}
|
||||
|
||||
fileprivate let textSubject = PublishSubject<String?>()
|
||||
|
||||
/// Typed parent object.
|
||||
@ -33,7 +29,7 @@ open class RxTextFieldDelegateProxy
|
||||
/// Initializes `RxTextFieldDelegateProxy`
|
||||
///
|
||||
/// - parameter parentObject: Parent object for delegate proxy.
|
||||
public required init(parentObject: ParentObject) {
|
||||
public init(parentObject: ParentObject) {
|
||||
self.textField = parentObject
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
|
@ -17,10 +17,6 @@ class RxCLLocationManagerDelegateProxy
|
||||
, DelegateProxyType
|
||||
, CLLocationManagerDelegate {
|
||||
|
||||
static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: RxCLLocationManagerDelegateProxy.self)
|
||||
}
|
||||
|
||||
internal lazy var didUpdateLocationsSubject = PublishSubject<[CLLocation]>()
|
||||
internal lazy var didFailWithErrorSubject = PublishSubject<Error>()
|
||||
|
||||
|
@ -24,7 +24,7 @@ extension DelegateProxyTest {
|
||||
class ExtendNSTextFieldDelegateProxy
|
||||
: RxTextFieldDelegateProxy
|
||||
, TestDelegateProtocol {
|
||||
required init(parentObject: ParentObject) {
|
||||
override init(parentObject: ParentObject) {
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,11 @@ import XCTest
|
||||
|
||||
extension DelegateProxyTest {
|
||||
func test_UITableViewDelegateExtension() {
|
||||
performDelegateTest(UITableViewSubclass1(frame: CGRect.zero), proxyType: ExtendTableViewDelegateProxy.self)
|
||||
performDelegateTest(UITableViewSubclass1(frame: CGRect.zero)) { ExtendTableViewDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
func test_UITableViewDataSourceExtension() {
|
||||
performDelegateTest(UITableViewSubclass2(frame: CGRect.zero), proxyType: ExtendTableViewDataSourceProxy.self)
|
||||
performDelegateTest(UITableViewSubclass2(frame: CGRect.zero)) { ExtendTableViewDataSourceProxy(parentObject: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,55 +28,55 @@ extension DelegateProxyTest {
|
||||
|
||||
func test_UICollectionViewDelegateExtension() {
|
||||
let layout = UICollectionViewFlowLayout()
|
||||
performDelegateTest(UICollectionViewSubclass1(frame: CGRect.zero, collectionViewLayout: layout), proxyType: ExtendCollectionViewDelegateProxy.self)
|
||||
performDelegateTest(UICollectionViewSubclass1(frame: CGRect.zero, collectionViewLayout: layout)) { ExtendCollectionViewDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
func test_UICollectionViewDataSourceExtension() {
|
||||
let layout = UICollectionViewFlowLayout()
|
||||
performDelegateTest(UICollectionViewSubclass2(frame: CGRect.zero, collectionViewLayout: layout), proxyType: ExtendCollectionViewDataSourceProxy.self)
|
||||
performDelegateTest(UICollectionViewSubclass2(frame: CGRect.zero, collectionViewLayout: layout)) { ExtendCollectionViewDataSourceProxy(parentObject: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
extension DelegateProxyTest {
|
||||
func test_UINavigationControllerDelegateExtension() {
|
||||
performDelegateTest(UINavigationControllerSubclass(), proxyType: ExtendNavigationControllerDelegateProxy.self)
|
||||
performDelegateTest(UINavigationControllerSubclass()) { ExtendNavigationControllerDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
extension DelegateProxyTest {
|
||||
func test_UIScrollViewDelegateExtension() {
|
||||
performDelegateTest(UIScrollViewSubclass(frame: CGRect.zero), proxyType: ExtendScrollViewDelegateProxy.self)
|
||||
performDelegateTest(UIScrollViewSubclass(frame: CGRect.zero)) { ExtendScrollViewDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
extension DelegateProxyTest {
|
||||
func test_UISearchBarDelegateExtension() {
|
||||
performDelegateTest(UISearchBarSubclass(frame: CGRect.zero), proxyType: ExtendSearchBarDelegateProxy.self)
|
||||
performDelegateTest(UISearchBarSubclass(frame: CGRect.zero)) { ExtendSearchBarDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extension DelegateProxyTest {
|
||||
func test_UITextViewDelegateExtension() {
|
||||
performDelegateTest(UITextViewSubclass(frame: CGRect.zero), proxyType: ExtendTextViewDelegateProxy.self)
|
||||
performDelegateTest(UITextViewSubclass(frame: CGRect.zero)) { ExtendTextViewDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
extension DelegateProxyTest {
|
||||
func test_UISearchController() {
|
||||
performDelegateTest(UISearchControllerSubclass(), proxyType: ExtendSearchControllerDelegateProxy.self)
|
||||
performDelegateTest(UISearchControllerSubclass()) { ExtendSearchControllerDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
extension DelegateProxyTest {
|
||||
func test_UIPickerViewExtension() {
|
||||
performDelegateTest(UIPickerViewSubclass(frame: CGRect.zero), proxyType: ExtendPickerViewDelegateProxy.self)
|
||||
performDelegateTest(UIPickerViewSubclass(frame: CGRect.zero)) { ExtendPickerViewDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
func test_UIPickerViewDataSourceExtension() {
|
||||
performDelegateTest(UIPickerViewSubclass2(frame: CGRect.zero), proxyType: ExtendPickerViewDataSourceProxy.self)
|
||||
performDelegateTest(UIPickerViewSubclass2(frame: CGRect.zero)) { ExtendPickerViewDataSourceProxy(parentObject: $0) }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -84,20 +84,20 @@ extension DelegateProxyTest {
|
||||
#if os(iOS)
|
||||
extension DelegateProxyTest {
|
||||
func test_UIWebViewDelegateExtension() {
|
||||
performDelegateTest(UIWebViewSubclass(frame: CGRect.zero), proxyType: ExtendWebViewDelegateProxy.self)
|
||||
performDelegateTest(UIWebViewSubclass(frame: CGRect.zero)) { ExtendWebViewDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extension DelegateProxyTest {
|
||||
func test_UITabBarControllerDelegateExtension() {
|
||||
performDelegateTest(UITabBarControllerSubclass(), proxyType: ExtendTabBarControllerDelegateProxy.self)
|
||||
performDelegateTest(UITabBarControllerSubclass()) { ExtendTabBarControllerDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
extension DelegateProxyTest {
|
||||
func test_UITabBarDelegateExtension() {
|
||||
performDelegateTest(UITabBarSubclass(), proxyType: ExtendTabBarDelegateProxy.self)
|
||||
performDelegateTest(UITabBarSubclass()) { ExtendTabBarDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ final class ExtendTableViewDelegateProxy
|
||||
, TestDelegateProtocol {
|
||||
weak fileprivate(set) var control: UITableViewSubclass1?
|
||||
|
||||
required init(parentObject: ParentObject) {
|
||||
override init(parentObject: UITableView) {
|
||||
self.control = parentObject as? UITableViewSubclass1
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
@ -142,8 +142,8 @@ final class ExtendTableViewDataSourceProxy
|
||||
, TestDelegateProtocol {
|
||||
weak fileprivate(set) var control: UITableViewSubclass2?
|
||||
|
||||
required init(parentObject: ParentObject) {
|
||||
self.control = parentObject as? UITableViewSubclass2
|
||||
init(parentObject: UITableViewSubclass2) {
|
||||
self.control = parentObject
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
}
|
||||
@ -171,8 +171,8 @@ final class ExtendCollectionViewDelegateProxy
|
||||
, TestDelegateProtocol {
|
||||
weak fileprivate(set) var control: UICollectionViewSubclass1?
|
||||
|
||||
required init(parentObject: ParentObject) {
|
||||
self.control = parentObject as? UICollectionViewSubclass1
|
||||
init(parentObject: UICollectionViewSubclass1) {
|
||||
self.control = parentObject
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
}
|
||||
@ -198,8 +198,8 @@ final class ExtendCollectionViewDataSourceProxy
|
||||
, TestDelegateProtocol {
|
||||
weak fileprivate(set) var control: UICollectionViewSubclass2?
|
||||
|
||||
required init(parentObject: ParentObject) {
|
||||
self.control = parentObject as? UICollectionViewSubclass2
|
||||
init(parentObject: UICollectionViewSubclass2) {
|
||||
self.control = parentObject
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
}
|
||||
@ -228,7 +228,7 @@ final class ExtendScrollViewDelegateProxy
|
||||
, TestDelegateProtocol {
|
||||
weak fileprivate(set) var control: UIScrollViewSubclass?
|
||||
|
||||
required init(parentObject: ParentObject) {
|
||||
override init(parentObject: ParentObject) {
|
||||
self.control = parentObject as? UIScrollViewSubclass
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
@ -256,7 +256,7 @@ final class ExtendSearchBarDelegateProxy
|
||||
, TestDelegateProtocol {
|
||||
weak fileprivate(set) var control: UISearchBarSubclass?
|
||||
|
||||
required init(parentObject: ParentObject) {
|
||||
override init(parentObject: ParentObject) {
|
||||
self.control = parentObject as? UISearchBarSubclass
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
@ -284,8 +284,8 @@ final class ExtendTextViewDelegateProxy
|
||||
, TestDelegateProtocol {
|
||||
weak fileprivate(set) var control: UITextViewSubclass?
|
||||
|
||||
required init(parentObject: ParentObject) {
|
||||
self.control = parentObject as? UITextViewSubclass
|
||||
init(parentObject: UITextViewSubclass) {
|
||||
self.control = parentObject
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
}
|
||||
@ -309,7 +309,7 @@ final class UITextViewSubclass
|
||||
final class ExtendSearchControllerDelegateProxy
|
||||
: RxSearchControllerDelegateProxy
|
||||
, TestDelegateProtocol {
|
||||
required init(parentObject: ParentObject) {
|
||||
override init(parentObject: ParentObject) {
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
}
|
||||
@ -334,7 +334,7 @@ final class UISearchControllerSubclass
|
||||
final class ExtendPickerViewDelegateProxy
|
||||
: RxPickerViewDelegateProxy
|
||||
, TestDelegateProtocol {
|
||||
required init(parentObject: ParentObject) {
|
||||
override init(parentObject: ParentObject) {
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
}
|
||||
@ -362,8 +362,8 @@ final class ExtendPickerViewDataSourceProxy
|
||||
, TestDelegateProtocol {
|
||||
weak fileprivate(set) var control: UIPickerViewSubclass2?
|
||||
|
||||
required init(parentObject: ParentObject) {
|
||||
self.control = parentObject as! UIPickerViewSubclass2
|
||||
init(parentObject: UIPickerViewSubclass2) {
|
||||
self.control = parentObject
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
}
|
||||
@ -387,7 +387,7 @@ final class UIPickerViewSubclass2: UIPickerView, TestDelegateControl {
|
||||
final class ExtendWebViewDelegateProxy
|
||||
: RxWebViewDelegateProxy
|
||||
, TestDelegateProtocol {
|
||||
required init(parentObject: ParentObject) {
|
||||
override init(parentObject: ParentObject) {
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
}
|
||||
@ -417,7 +417,7 @@ final class ExtendTextStorageDelegateProxy
|
||||
: RxTextStorageDelegateProxy
|
||||
, TestDelegateProtocol {
|
||||
|
||||
required init(parentObject: ParentObject) {
|
||||
override init(parentObject: ParentObject) {
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
}
|
||||
@ -443,7 +443,7 @@ final class ExtendNavigationControllerDelegateProxy
|
||||
, TestDelegateProtocol {
|
||||
weak fileprivate(set) var control: UINavigationControllerSubclass?
|
||||
|
||||
required init(parentObject: ParentObject) {
|
||||
override init(parentObject: ParentObject) {
|
||||
self.control = parentObject as? UINavigationControllerSubclass
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
@ -454,7 +454,7 @@ final class ExtendTabBarControllerDelegateProxy
|
||||
, TestDelegateProtocol {
|
||||
weak fileprivate(set) var control: UITabBarControllerSubclass?
|
||||
|
||||
required init(parentObject: ParentObject) {
|
||||
override init(parentObject: ParentObject) {
|
||||
self.control = parentObject as? UITabBarControllerSubclass
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
@ -465,7 +465,7 @@ final class ExtendTabBarDelegateProxy
|
||||
, TestDelegateProtocol {
|
||||
weak fileprivate(set) var control: UITabBarSubclass?
|
||||
|
||||
required init(parentObject: ParentObject) {
|
||||
override init(parentObject: ParentObject) {
|
||||
self.control = parentObject as? UITabBarSubclass
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
|
@ -315,22 +315,18 @@ extension DelegateProxyTest {
|
||||
func test_delegateProxyType() {
|
||||
let view = InitialClassView()
|
||||
let subclassView = InitialClassViewSubclass()
|
||||
let proxy1 = InitialClassViewDelegateProxy.createProxy(for: view)
|
||||
_ = InitialClassViewDelegateProxy.createProxy(for: view)
|
||||
let proxy2 = InitialClassViewDelegateProxy.createProxy(for: subclassView)
|
||||
XCTAssert(proxy1 is InitialClassViewDelegateProxy)
|
||||
XCTAssert(proxy2 is InitialClassViewDelegateProxySubclass)
|
||||
}
|
||||
|
||||
func test_delegateProxyTypeExtend_a() {
|
||||
let extendView1 = InitialClassViewSometimeExtended1_a()
|
||||
let extendView2 = InitialClassViewSometimeExtended2_a()
|
||||
let proxy1 = InitialClassViewDelegateProxy.createProxy(for: extendView1)
|
||||
let proxy2 = InitialClassViewDelegateProxy.createProxy(for: extendView2)
|
||||
XCTAssert(proxy1 is InitialClassViewDelegateProxy)
|
||||
XCTAssert(proxy2 is InitialClassViewDelegateProxy)
|
||||
|
||||
ExtendClassViewDelegateProxy_a.register(for: InitialClassViewSometimeExtended1_a.self)
|
||||
_ = InitialClassViewDelegateProxy.createProxy(for: extendView1)
|
||||
_ = InitialClassViewDelegateProxy.createProxy(for: extendView2)
|
||||
|
||||
ExtendClassViewDelegateProxy_a.register { ExtendClassViewDelegateProxy_a(parentObject1: $0) }
|
||||
|
||||
let extendedProxy1 = InitialClassViewDelegateProxy.createProxy(for: extendView1)
|
||||
let extendedProxy2 = InitialClassViewDelegateProxy.createProxy(for: extendView2)
|
||||
@ -341,16 +337,13 @@ extension DelegateProxyTest {
|
||||
func test_delegateProxyTypeExtend_b() {
|
||||
let extendView1 = InitialClassViewSometimeExtended1_b()
|
||||
let extendView2 = InitialClassViewSometimeExtended2_b()
|
||||
let proxy1 = InitialClassViewDelegateProxy.createProxy(for: extendView1)
|
||||
let proxy2 = InitialClassViewDelegateProxy.createProxy(for: extendView2)
|
||||
XCTAssert(proxy1 is InitialClassViewDelegateProxy)
|
||||
XCTAssert(proxy2 is InitialClassViewDelegateProxy)
|
||||
_ = InitialClassViewDelegateProxy.createProxy(for: extendView1)
|
||||
_ = InitialClassViewDelegateProxy.createProxy(for: extendView2)
|
||||
|
||||
ExtendClassViewDelegateProxy_b.register(for: InitialClassViewSometimeExtended2_b.self)
|
||||
ExtendClassViewDelegateProxy_b.register { ExtendClassViewDelegateProxy_b(parentObject2: $0) }
|
||||
|
||||
let extendedProxy1 = InitialClassViewDelegateProxy.createProxy(for: extendView1)
|
||||
_ = InitialClassViewDelegateProxy.createProxy(for: extendView1)
|
||||
let extendedProxy2 = InitialClassViewDelegateProxy.createProxy(for: extendView2)
|
||||
XCTAssert(extendedProxy1 is InitialClassViewDelegateProxy)
|
||||
XCTAssert(extendedProxy2 is ExtendClassViewDelegateProxy_b)
|
||||
}
|
||||
}
|
||||
@ -368,8 +361,8 @@ extension DelegateProxyTest {
|
||||
// MARK: Testing extensions
|
||||
|
||||
extension DelegateProxyTest {
|
||||
func performDelegateTest<Control: TestDelegateControl, ExtendedProxy: DelegateProxyType>( _ createControl: @autoclosure() -> Control, proxyType: ExtendedProxy.Type) {
|
||||
ExtendedProxy.register(for: Control.self as! ExtendedProxy.ParentObject.Type)
|
||||
func performDelegateTest<Control: TestDelegateControl, ExtendedProxy: DelegateProxyType>( _ createControl: @autoclosure() -> Control, make: @escaping (Control) -> ExtendedProxy) {
|
||||
ExtendedProxy.register(make: make)
|
||||
var control: Control!
|
||||
|
||||
autoreleasepool {
|
||||
@ -467,11 +460,12 @@ final class ThreeDSectionedViewDelegateProxy: DelegateProxy<ThreeDSectionedView,
|
||||
, ThreeDSectionedViewProtocol
|
||||
, DelegateProxyType {
|
||||
|
||||
public static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: ThreeDSectionedViewDelegateProxy.self)
|
||||
// Register known implementations
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { ThreeDSectionedViewDelegateProxy(parentObject: $0) }
|
||||
}
|
||||
|
||||
required init(parentObject: ThreeDSectionedView) {
|
||||
override init(parentObject: ThreeDSectionedView) {
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
|
||||
@ -564,12 +558,11 @@ class InitialClassViewDelegateProxy
|
||||
: DelegateProxy<InitialClassView, InitialClassViewDelegate>
|
||||
, DelegateProxyType
|
||||
, InitialClassViewDelegate {
|
||||
static var factory: DelegateProxyFactory {
|
||||
return DelegateProxyFactory.sharedFactory(for: InitialClassViewDelegateProxy.self)
|
||||
}
|
||||
|
||||
static func knownImplementations() {
|
||||
InitialClassViewDelegateProxySubclass.register(for: InitialClassViewSubclass.self)
|
||||
|
||||
// Register known implementations
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { InitialClassViewDelegateProxy(parentObject: $0) }
|
||||
self.register { InitialClassViewDelegateProxySubclass(parentObject: $0) }
|
||||
}
|
||||
|
||||
static override func currentDelegate(for object: ParentObject) -> InitialClassViewDelegate? {
|
||||
@ -582,11 +575,13 @@ class InitialClassViewDelegateProxy
|
||||
}
|
||||
|
||||
class InitialClassViewDelegateProxySubclass: InitialClassViewDelegateProxy {
|
||||
|
||||
init(parentObject: InitialClassViewSubclass) {
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
}
|
||||
|
||||
class InitialClassViewSometimeExtended1_a: InitialClassView {
|
||||
|
||||
|
||||
}
|
||||
|
||||
class InitialClassViewSometimeExtended2_a: InitialClassViewSometimeExtended1_a {
|
||||
@ -602,11 +597,23 @@ class InitialClassViewSometimeExtended2_b: InitialClassViewSometimeExtended1_b {
|
||||
}
|
||||
|
||||
class ExtendClassViewDelegateProxy_a: InitialClassViewDelegateProxy {
|
||||
|
||||
init(parentObject1: InitialClassViewSometimeExtended1_a) {
|
||||
super.init(parentObject: parentObject1)
|
||||
}
|
||||
|
||||
init(parentObject2: InitialClassViewSometimeExtended2_a) {
|
||||
super.init(parentObject: parentObject2)
|
||||
}
|
||||
}
|
||||
|
||||
class ExtendClassViewDelegateProxy_b: InitialClassViewDelegateProxy {
|
||||
|
||||
init(parentObject1: InitialClassViewSometimeExtended1_b) {
|
||||
super.init(parentObject: parentObject1)
|
||||
}
|
||||
|
||||
init(parentObject2: InitialClassViewSometimeExtended2_b) {
|
||||
super.init(parentObject: parentObject2)
|
||||
}
|
||||
}
|
||||
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user