File tree Expand file tree Collapse file tree 15 files changed +100
-145
lines changed Expand file tree Collapse file tree 15 files changed +100
-145
lines changed Original file line number Diff line number Diff line change @@ -242,6 +242,44 @@ extension DelegateProxyType
242
242
}
243
243
}
244
244
245
+ /// Describes an object that has a delegate.
246
+ public protocol HasDelegate : AnyObject {
247
+ /// Delegate type
248
+ associatedtype Delegate : AnyObject
249
+
250
+ /// Delegate
251
+ var delegate : Delegate ? { get set }
252
+ }
253
+
254
+ extension DelegateProxyType where ParentObject: HasDelegate , Self. Delegate == ParentObject . Delegate {
255
+ public static func currentDelegate( for object: ParentObject ) -> Delegate ? {
256
+ return object. delegate
257
+ }
258
+
259
+ public static func setCurrentDelegate( _ delegate: Delegate ? , to object: ParentObject ) {
260
+ object. delegate = delegate
261
+ }
262
+ }
263
+
264
+ /// Describes an object that has a data source.
265
+ public protocol HasDataSource : AnyObject {
266
+ /// Data source type
267
+ associatedtype DataSource : AnyObject
268
+
269
+ /// Data source
270
+ var dataSource : DataSource ? { get set }
271
+ }
272
+
273
+ extension DelegateProxyType where ParentObject: HasDataSource , Self. Delegate == ParentObject . DataSource {
274
+ public static func currentDelegate( for object: ParentObject ) -> Delegate ? {
275
+ return object. dataSource
276
+ }
277
+
278
+ public static func setCurrentDelegate( _ delegate: Delegate ? , to object: ParentObject ) {
279
+ object. dataSource = delegate
280
+ }
281
+ }
282
+
245
283
#if os(iOS) || os(tvOS)
246
284
import UIKit
247
285
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ import UIKit
13
13
import RxSwift
14
14
#endif
15
15
16
+ extension UICollectionView : HasDataSource {
17
+ public typealias DataSource = UICollectionViewDataSource
18
+ }
19
+
16
20
let collectionViewDataSourceNotSet = CollectionViewDataSourceNotSet ( )
17
21
18
22
final class CollectionViewDataSourceNotSet
@@ -64,18 +68,6 @@ open class RxCollectionViewDataSourceProxy
64
68
public func collectionView( _ collectionView: UICollectionView , cellForItemAt indexPath: IndexPath ) -> UICollectionViewCell {
65
69
return ( _requiredMethodsDataSource ?? collectionViewDataSourceNotSet) . collectionView ( collectionView, cellForItemAt: indexPath)
66
70
}
67
-
68
- // MARK: proxy
69
-
70
- /// For more information take a look at `DelegateProxyType`.
71
- open class func setCurrentDelegate( _ delegate: UICollectionViewDataSource ? , to object: ParentObject ) {
72
- object. dataSource = delegate
73
- }
74
-
75
- /// For more information take a look at `DelegateProxyType`.
76
- open class func currentDelegate( for object: ParentObject ) -> UICollectionViewDataSource ? {
77
- return object. dataSource
78
- }
79
71
80
72
/// For more information take a look at `DelegateProxyType`.
81
73
open override func setForwardToDelegate( _ forwardToDelegate: UICollectionViewDataSource ? , retainDelegate: Bool ) {
Original file line number Diff line number Diff line change 13
13
import RxSwift
14
14
#endif
15
15
16
+ extension UINavigationController : HasDelegate {
17
+ public typealias Delegate = UINavigationControllerDelegate
18
+ }
19
+
16
20
/// For more information take a look at `DelegateProxyType`.
17
21
open class RxNavigationControllerDelegateProxy
18
22
: DelegateProxy < UINavigationController , UINavigationControllerDelegate >
32
36
public static func registerKnownImplementations( ) {
33
37
self . register { RxNavigationControllerDelegateProxy ( parentObject: $0) }
34
38
}
35
-
36
- /// For more information take a look at `DelegateProxyType`.
37
- open class func currentDelegate( for object: ParentObject ) -> UINavigationControllerDelegate ? {
38
- return object. delegate
39
- }
40
-
41
- /// For more information take a look at `DelegateProxyType`.
42
- open class func setCurrentDelegate( _ delegate: UINavigationControllerDelegate ? , to object: ParentObject ) {
43
- object. delegate = delegate
44
- }
45
39
}
46
40
#endif
Original file line number Diff line number Diff line change 13
13
import RxSwift
14
14
#endif
15
15
16
+ extension UIPickerView : HasDataSource {
17
+ public typealias DataSource = UIPickerViewDataSource
18
+ }
19
+
16
20
fileprivate let pickerViewDataSourceNotSet = PickerViewDataSourceNotSet ( )
17
21
18
22
final fileprivate class PickerViewDataSourceNotSet : NSObject , UIPickerViewDataSource {
@@ -59,18 +63,6 @@ public class RxPickerViewDataSourceProxy
59
63
return ( _requiredMethodsDataSource ?? pickerViewDataSourceNotSet) . pickerView ( pickerView, numberOfRowsInComponent: component)
60
64
}
61
65
62
- // MARK: proxy
63
-
64
- /// For more information take a look at `DelegateProxyType`.
65
- public class func setCurrentDelegate( _ delegate: UIPickerViewDataSource ? , to object: UIPickerView ) {
66
- object. dataSource = delegate
67
- }
68
-
69
- /// For more information take a look at `DelegateProxyType`.
70
- public class func currentDelegate( for object: UIPickerView ) -> UIPickerViewDataSource ? {
71
- return object. dataSource
72
- }
73
-
74
66
/// For more information take a look at `DelegateProxyType`.
75
67
public override func setForwardToDelegate( _ forwardToDelegate: UIPickerViewDataSource ? , retainDelegate: Bool ) {
76
68
_requiredMethodsDataSource = forwardToDelegate ?? pickerViewDataSourceNotSet
Original file line number Diff line number Diff line change 13
13
#endif
14
14
import UIKit
15
15
16
+ extension UIPickerView : HasDelegate {
17
+ public typealias Delegate = UIPickerViewDelegate
18
+ }
19
+
16
20
open class RxPickerViewDelegateProxy
17
21
: DelegateProxy < UIPickerView , UIPickerViewDelegate >
18
22
, DelegateProxyType
31
35
public static func registerKnownImplementations( ) {
32
36
self . register { RxPickerViewDelegateProxy ( parentObject: $0) }
33
37
}
34
-
35
- /// For more information take a look at `DelegateProxyType`.
36
- open class func setCurrentDelegate( _ delegate: UIPickerViewDelegate ? , to object: ParentObject ) {
37
- object. delegate = delegate
38
- }
39
-
40
- /// For more information take a look at `DelegateProxyType`.
41
- open class func currentDelegate( for object: ParentObject ) -> UIPickerViewDelegate ? {
42
- return object. delegate
43
- }
44
38
}
45
39
#endif
Original file line number Diff line number Diff line change 12
12
import RxSwift
13
13
#endif
14
14
import UIKit
15
+
16
+ extension UIScrollView : HasDelegate {
17
+ public typealias Delegate = UIScrollViewDelegate
18
+ }
15
19
16
20
/// For more information take a look at `DelegateProxyType`.
17
21
open class RxScrollViewDelegateProxy
@@ -76,18 +80,6 @@ open class RxScrollViewDelegateProxy
76
80
self . _forwardToDelegate? . scrollViewDidScroll ? ( scrollView)
77
81
}
78
82
79
- // MARK: delegate proxy
80
-
81
- /// For more information take a look at `DelegateProxyType`.
82
- open class func setCurrentDelegate( _ delegate: UIScrollViewDelegate ? , to object: ParentObject ) {
83
- object. delegate = delegate
84
- }
85
-
86
- /// For more information take a look at `DelegateProxyType`.
87
- open class func currentDelegate( for object: ParentObject ) -> UIScrollViewDelegate ? {
88
- return object. delegate
89
- }
90
-
91
83
deinit {
92
84
if let subject = _contentOffsetBehaviorSubject {
93
85
subject. on ( . completed)
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ import UIKit
13
13
import RxSwift
14
14
#endif
15
15
16
+ extension UISearchBar : HasDelegate {
17
+ public typealias Delegate = UISearchBarDelegate
18
+ }
19
+
16
20
/// For more information take a look at `DelegateProxyType`.
17
21
open class RxSearchBarDelegateProxy
18
22
: DelegateProxy < UISearchBar , UISearchBarDelegate >
@@ -32,18 +36,6 @@ open class RxSearchBarDelegateProxy
32
36
public static func registerKnownImplementations( ) {
33
37
self . register { RxSearchBarDelegateProxy ( parentObject: $0) }
34
38
}
35
-
36
- // MARK: Delegate proxy methods
37
-
38
- /// For more information take a look at `DelegateProxyType`.
39
- open class func currentDelegate( for object: ParentObject ) -> UISearchBarDelegate ? {
40
- return object. delegate
41
- }
42
-
43
- /// For more information take a look at `DelegateProxyType`.
44
- open class func setCurrentDelegate( _ delegate: UISearchBarDelegate ? , to object: ParentObject ) {
45
- object. delegate = delegate
46
- }
47
39
}
48
40
49
41
#endif
Original file line number Diff line number Diff line change 13
13
#endif
14
14
import UIKit
15
15
16
+ extension UISearchController : HasDelegate {
17
+ public typealias Delegate = UISearchControllerDelegate
18
+ }
19
+
16
20
/// For more information take a look at `DelegateProxyType`.
17
21
@available ( iOS 8 . 0 , * )
18
22
open class RxSearchControllerDelegateProxy
@@ -33,17 +37,6 @@ open class RxSearchControllerDelegateProxy
33
37
public static func registerKnownImplementations( ) {
34
38
self . register { RxSearchControllerDelegateProxy ( parentObject: $0) }
35
39
}
36
-
37
- /// For more information take a look at `DelegateProxyType`.
38
- open class func setCurrentDelegate( _ delegate: UISearchControllerDelegate ? , to object: ParentObject ) {
39
- object. delegate = delegate
40
- }
41
-
42
- /// For more information take a look at `DelegateProxyType`.
43
- open class func currentDelegate( for object: ParentObject ) -> UISearchControllerDelegate ? {
44
- return object. delegate
45
- }
46
-
47
40
}
48
41
49
42
#endif
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ import UIKit
13
13
import RxSwift
14
14
#endif
15
15
16
+ extension UITabBarController : HasDelegate {
17
+ public typealias Delegate = UITabBarControllerDelegate
18
+ }
19
+
16
20
/// For more information take a look at `DelegateProxyType`.
17
21
open class RxTabBarControllerDelegateProxy
18
22
: DelegateProxy < UITabBarController , UITabBarControllerDelegate >
@@ -32,16 +36,6 @@ open class RxTabBarControllerDelegateProxy
32
36
public static func registerKnownImplementations( ) {
33
37
self . register { RxTabBarControllerDelegateProxy ( parentObject: $0) }
34
38
}
35
-
36
- /// For more information take a look at `DelegateProxyType`.
37
- open class func currentDelegate( for object: ParentObject ) -> UITabBarControllerDelegate ? {
38
- return object. delegate
39
- }
40
-
41
- /// For more information take a look at `DelegateProxyType`.
42
- open class func setCurrentDelegate( _ delegate: UITabBarControllerDelegate ? , to object: ParentObject ) {
43
- object. delegate = delegate
44
- }
45
39
}
46
40
47
41
#endif
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ import UIKit
13
13
import RxSwift
14
14
#endif
15
15
16
+ extension UITabBar : HasDelegate {
17
+ public typealias Delegate = UITabBarDelegate
18
+ }
19
+
16
20
/// For more information take a look at `DelegateProxyType`.
17
21
open class RxTabBarDelegateProxy
18
22
: DelegateProxy < UITabBar , UITabBarDelegate >
Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ import UIKit
12
12
#if !RX_NO_MODULE
13
13
import RxSwift
14
14
#endif
15
+
16
+ extension UITableView : HasDataSource {
17
+ public typealias DataSource = UITableViewDataSource
18
+ }
15
19
16
20
let tableViewDataSourceNotSet = TableViewDataSourceNotSet ( )
17
21
@@ -61,18 +65,6 @@ open class RxTableViewDataSourceProxy
61
65
public func tableView( _ tableView: UITableView , cellForRowAt indexPath: IndexPath ) -> UITableViewCell {
62
66
return ( _requiredMethodsDataSource ?? tableViewDataSourceNotSet) . tableView ( tableView, cellForRowAt: indexPath)
63
67
}
64
-
65
- // MARK: proxy
66
-
67
- /// For more information take a look at `DelegateProxyType`.
68
- open class func setCurrentDelegate( _ delegate: UITableViewDataSource ? , to object: ParentObject ) {
69
- object. dataSource = delegate
70
- }
71
-
72
- /// For more information take a look at `DelegateProxyType`.
73
- open class func currentDelegate( for object: ParentObject ) -> UITableViewDataSource ? {
74
- return object. dataSource
75
- }
76
68
77
69
/// For more information take a look at `DelegateProxyType`.
78
70
open override func setForwardToDelegate( _ forwardToDelegate: UITableViewDataSource ? , retainDelegate: Bool ) {
Original file line number Diff line number Diff line change 12
12
import RxSwift
13
13
#endif
14
14
import UIKit
15
-
15
+
16
+ extension NSTextStorage : HasDelegate {
17
+ public typealias Delegate = NSTextStorageDelegate
18
+ }
19
+
16
20
open class RxTextStorageDelegateProxy
17
21
: DelegateProxy < NSTextStorage , NSTextStorageDelegate >
18
22
, DelegateProxyType
31
35
public static func registerKnownImplementations( ) {
32
36
self . register { RxTextStorageDelegateProxy ( parentObject: $0) }
33
37
}
34
-
35
- /// For more information take a look at `DelegateProxyType`.
36
- open class func setCurrentDelegate( _ delegate: NSTextStorageDelegate ? , to object: ParentObject ) {
37
- object. delegate = delegate
38
- }
39
-
40
- /// For more information take a look at `DelegateProxyType`.
41
- open class func currentDelegate( for object: ParentObject ) -> NSTextStorageDelegate ? {
42
- return object. delegate
43
- }
44
38
}
45
39
#endif
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ import UIKit
13
13
import RxSwift
14
14
#endif
15
15
16
+ extension UIWebView : HasDelegate {
17
+ public typealias Delegate = UIWebViewDelegate
18
+ }
19
+
16
20
open class RxWebViewDelegateProxy
17
21
: DelegateProxy < UIWebView , UIWebViewDelegate >
18
22
, DelegateProxyType
@@ -31,16 +35,6 @@ open class RxWebViewDelegateProxy
31
35
public static func registerKnownImplementations( ) {
32
36
self . register { RxWebViewDelegateProxy ( parentObject: $0) }
33
37
}
34
-
35
- /// For more information take a look at `DelegateProxyType`.
36
- open class func setCurrentDelegate( _ delegate: UIWebViewDelegate ? , to object: UIWebView ) {
37
- object. delegate = delegate
38
- }
39
-
40
- /// For more information take a look at `DelegateProxyType`.
41
- open class func currentDelegate( for object: UIWebView ) -> UIWebViewDelegate ? {
42
- return object. delegate
43
- }
44
38
}
45
39
46
40
#endif
Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ import CoreLocation
12
12
import RxCocoa
13
13
#endif
14
14
15
+ extension CLLocationManager : HasDelegate {
16
+ public typealias Delegate = CLLocationManagerDelegate
17
+ }
18
+
15
19
public class RxCLLocationManagerDelegateProxy
16
20
: DelegateProxy < CLLocationManager , CLLocationManagerDelegate >
17
21
, DelegateProxyType
@@ -28,14 +32,6 @@ public class RxCLLocationManagerDelegateProxy
28
32
internal lazy var didUpdateLocationsSubject = PublishSubject < [ CLLocation ] > ( )
29
33
internal lazy var didFailWithErrorSubject = PublishSubject < Error > ( )
30
34
31
- public class func currentDelegate( for object: ParentObject ) -> CLLocationManagerDelegate ? {
32
- return object. delegate
33
- }
34
-
35
- public class func setCurrentDelegate( _ delegate: CLLocationManagerDelegate ? , to object: ParentObject ) {
36
- object. delegate = delegate
37
- }
38
-
39
35
public func locationManager( _ manager: CLLocationManager , didUpdateLocations locations: [ CLLocation ] ) {
40
36
_forwardToDelegate? . locationManager ? ( manager, didUpdateLocations: locations)
41
37
didUpdateLocationsSubject. onNext ( locations)
You can’t perform that action at this time.
0 commit comments