Skip to content

Commit 16f6c3a

Browse files
committed
Avoid use unsafeDowncast. Remove generics parameter from DelegateProxy subclasses subclass.
1 parent c4bfcd3 commit 16f6c3a

39 files changed

+156
-156
lines changed

RxCocoa/Common/DelegateProxyFactory.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ public class DelegateProxyFactory {
6363

6464
private init<DelegateProxy: DelegateProxyType>(for proxyType: DelegateProxy.Type) {
6565
_factories = [:]
66-
self.extend(with: proxyType)
66+
self.extend(with: proxyType, for: DelegateProxy.ParentObject.self)
6767
}
6868

6969
/**
7070
Extend DelegateProxyFactory for specific object class and delegate proxy.
7171
Define object class on closure argument.
7272
*/
73-
internal func extend<DelegateProxy: DelegateProxyType>(with proxyType: DelegateProxy.Type) {
73+
internal func extend<DelegateProxy: DelegateProxyType>(with proxyType: DelegateProxy.Type, for parentObjectType: DelegateProxy.ParentObject.Type) {
7474
MainScheduler.ensureExecutingOnScheduler()
7575
assert((DelegateProxy.self as? DelegateProxy.Delegate) != nil, "DelegateProxy subclass should be as a Delegate")
76-
guard _factories[ObjectIdentifier(DelegateProxy.ParentObject.self)] == nil else {
77-
rxFatalError("The factory of \(DelegateProxy.ParentObject.self) is duplicated. DelegateProxy is not allowed of duplicated base object type.")
76+
guard _factories[ObjectIdentifier(parentObjectType)] == nil else {
77+
rxFatalError("The factory of \(parentObjectType) is duplicated. DelegateProxy is not allowed of duplicated base object type.")
7878
}
79-
_factories[ObjectIdentifier(DelegateProxy.ParentObject.self)] = { proxyType.init(parentObject: castOrFatalError($0)) }
79+
_factories[ObjectIdentifier(parentObjectType)] = { proxyType.init(parentObject: castOrFatalError($0)) }
8080
}
8181

8282
/**

RxCocoa/Common/DelegateProxyType.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ extension DelegateProxyType {
157157
/// When make 'Rx*DelegateProxy' subclass, call 'Rx*DelegateProxySubclass.register()' 1 time, or use it in DelegateProxyFactory
158158
/// 'Rx*DelegateProxy' can have one subclass implementation per concrete ParentObject type.
159159
/// Should call it from concrete DelegateProxy type, not generic.
160-
public static func register() {
161-
self.factory.extend(with: self)
160+
public static func register(for parentObjectType: ParentObject.Type) {
161+
self.factory.extend(with: self, for: parentObjectType)
162162
}
163163

164164
/// It is require that enumerate call `register` of the extended DelegateProxy subclasses here.
@@ -206,7 +206,7 @@ extension DelegateProxyType {
206206
assert(self.assignedProxy(for: object) === proxy)
207207
}
208208
let currentDelegate = self.currentDelegate(for: object)
209-
let delegateProxy = unsafeDowncast(proxy, to: self)
209+
let delegateProxy: Self = castOrFatalError(proxy)
210210

211211
if currentDelegate !== delegateProxy {
212212
delegateProxy.setForwardToDelegate(currentDelegate, retainDelegate: false)

RxCocoa/Deprecated.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,63 +138,63 @@ extension ObservableType {
138138

139139
extension NSTextStorage {
140140
@available(*, unavailable, message: "createRxDelegateProxy is now unavailable, check DelegateProxyFactory")
141-
public func createRxDelegateProxy() -> RxTextStorageDelegateProxy<NSTextStorage> {
141+
public func createRxDelegateProxy() -> RxTextStorageDelegateProxy {
142142
fatalError()
143143
}
144144
}
145145

146146
extension UIScrollView {
147147
@available(*, unavailable, message: "createRxDelegateProxy is now unavailable, check DelegateProxyFactory")
148-
public func createRxDelegateProxy() -> RxScrollViewDelegateProxy<UIScrollView> {
148+
public func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
149149
fatalError()
150150
}
151151
}
152152

153153
extension UICollectionView {
154154
@available(*, unavailable, message: "createRxDataSourceProxy is now unavailable, check DelegateProxyFactory")
155-
public func createRxDataSourceProxy() -> RxCollectionViewDataSourceProxy<UICollectionView> {
155+
public func createRxDataSourceProxy() -> RxCollectionViewDataSourceProxy {
156156
fatalError()
157157
}
158158
}
159159

160160
extension UITableView {
161161
@available(*, unavailable, message: "createRxDataSourceProxy is now unavailable, check DelegateProxyFactory")
162-
public func createRxDataSourceProxy() -> RxTableViewDataSourceProxy<UITableView> {
162+
public func createRxDataSourceProxy() -> RxTableViewDataSourceProxy {
163163
fatalError()
164164
}
165165
}
166166

167167
extension UINavigationBar {
168168
@available(*, unavailable, message: "createRxDelegateProxy is now unavailable, check DelegateProxyFactory")
169-
public func createRxDelegateProxy() -> RxNavigationControllerDelegateProxy<UINavigationController> {
169+
public func createRxDelegateProxy() -> RxNavigationControllerDelegateProxy {
170170
fatalError()
171171
}
172172
}
173173

174174
extension UINavigationController {
175175
@available(*, unavailable, message: "createRxDelegateProxy is now unavailable, check DelegateProxyFactory")
176-
public func createRxDelegateProxy() -> RxNavigationControllerDelegateProxy<UINavigationController> {
176+
public func createRxDelegateProxy() -> RxNavigationControllerDelegateProxy {
177177
fatalError()
178178
}
179179
}
180180

181181
extension UITabBar {
182182
@available(*, unavailable, message: "createRxDelegateProxy is now unavailable, check DelegateProxyFactory")
183-
public func createRxDelegateProxy() -> RxTabBarDelegateProxy<UITabBar> {
183+
public func createRxDelegateProxy() -> RxTabBarDelegateProxy {
184184
fatalError()
185185
}
186186
}
187187

188188
extension UITabBarController {
189189
@available(*, unavailable, message: "createRxDelegateProxy is now unavailable, check DelegateProxyFactory")
190-
public func createRxDelegateProxy() -> RxTabBarControllerDelegateProxy<UITabBarController> {
190+
public func createRxDelegateProxy() -> RxTabBarControllerDelegateProxy {
191191
fatalError()
192192
}
193193
}
194194

195195
extension UISearchBar {
196196
@available(*, unavailable, message: "createRxDelegateProxy is now unavailable, check DelegateProxyFactory")
197-
public func createRxDelegateProxy() -> RxSearchBarDelegateProxy<UISearchBar> {
197+
public func createRxDelegateProxy() -> RxSearchBarDelegateProxy {
198198
fatalError()
199199
}
200200
}
@@ -204,25 +204,25 @@ extension ObservableType {
204204
#if os(iOS)
205205
extension UISearchController {
206206
@available(*, unavailable, message: "createRxDelegateProxy is now unavailable, check DelegateProxyFactory")
207-
public func createRxDelegateProxy() -> RxSearchControllerDelegateProxy<UISearchController> {
207+
public func createRxDelegateProxy() -> RxSearchControllerDelegateProxy {
208208
fatalError()
209209
}
210210
}
211211

212212
extension UIPickerView {
213213
@available(*, unavailable, message: "createRxDelegateProxy is now unavailable, check DelegateProxyFactory")
214-
public func createRxDelegateProxy() -> RxPickerViewDelegateProxy<UIPickerView> {
214+
public func createRxDelegateProxy() -> RxPickerViewDelegateProxy {
215215
fatalError()
216216
}
217217

218218
@available(*, unavailable, message: "createRxDataSourceProxy is now unavailable, check DelegateProxyFactory")
219-
public func createRxDataSourceProxy() -> RxPickerViewDataSourceProxy<UIPickerView> {
219+
public func createRxDataSourceProxy() -> RxPickerViewDataSourceProxy {
220220
fatalError()
221221
}
222222
}
223223
extension UIWebView {
224224
@available(*, unavailable, message: "createRxDelegateProxy is now unavailable, check DelegateProxyFactory")
225-
public func createRxDelegateProxy() -> RxWebViewDelegateProxy<UIWebView> {
225+
public func createRxDelegateProxy() -> RxWebViewDelegateProxy {
226226
fatalError()
227227
}
228228
}
@@ -233,7 +233,7 @@ extension ObservableType {
233233

234234
extension NSTextField {
235235
@available(*, unavailable, message: "createRxDelegateProxy is now unavailable, check DelegateProxyFactory")
236-
public func createRxDelegateProxy() -> RxTextFieldDelegateProxy<NSTextField> {
236+
public func createRxDelegateProxy() -> RxTextFieldDelegateProxy {
237237
fatalError()
238238
}
239239
}

RxCocoa/iOS/NSTextStorage+Rx.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/// Reactive wrapper for `delegate`.
1818
///
1919
/// For more information take a look at `DelegateProxyType` protocol documentation.
20-
public var delegate: DelegateProxy<Base, NSTextStorageDelegate> {
20+
public var delegate: DelegateProxy<NSTextStorage, NSTextStorageDelegate> {
2121
return RxTextStorageDelegateProxy.proxy(for: base)
2222
}
2323

RxCocoa/iOS/Proxies/RxCollectionViewDataSourceProxy.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ final class CollectionViewDataSourceNotSet
3232
}
3333

3434
/// For more information take a look at `DelegateProxyType`.
35-
open class RxCollectionViewDataSourceProxy<P: UICollectionView>
36-
: DelegateProxy<P, UICollectionViewDataSource>
35+
open class RxCollectionViewDataSourceProxy
36+
: DelegateProxy<UICollectionView, UICollectionViewDataSource>
3737
, DelegateProxyType
3838
, UICollectionViewDataSource {
3939

4040
public static var factory: DelegateProxyFactory {
41-
return DelegateProxyFactory.sharedFactory(for: RxCollectionViewDataSourceProxy<UICollectionView>.self)
41+
return DelegateProxyFactory.sharedFactory(for: RxCollectionViewDataSourceProxy.self)
4242
}
4343

4444
/// Typed parent object.

RxCocoa/iOS/Proxies/RxCollectionViewDelegateProxy.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import RxSwift
1414
#endif
1515

1616
/// For more information take a look at `DelegateProxyType`.
17-
open class RxCollectionViewDelegateProxy<P: UICollectionView>
18-
: RxScrollViewDelegateProxy<P>
17+
open class RxCollectionViewDelegateProxy
18+
: RxScrollViewDelegateProxy
1919
, UICollectionViewDelegate
2020
, UICollectionViewDelegateFlowLayout {
2121

@@ -26,7 +26,7 @@ open class RxCollectionViewDelegateProxy<P: UICollectionView>
2626
///
2727
/// - parameter parentObject: Parent object for delegate proxy.
2828
public required init(parentObject: ParentObject) {
29-
self.collectionView = parentObject
29+
self.collectionView = castOrFatalError(parentObject)
3030
super.init(parentObject: parentObject)
3131
}
3232
}

RxCocoa/iOS/Proxies/RxNavigationControllerDelegateProxy.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
#endif
1515

1616
/// For more information take a look at `DelegateProxyType`.
17-
open class RxNavigationControllerDelegateProxy<P: UINavigationController>
18-
: DelegateProxy<P, UINavigationControllerDelegate>
17+
open class RxNavigationControllerDelegateProxy
18+
: DelegateProxy<UINavigationController, UINavigationControllerDelegate>
1919
, DelegateProxyType
2020
, UINavigationControllerDelegate {
2121

2222
public static var factory: DelegateProxyFactory {
23-
return DelegateProxyFactory.sharedFactory(for: RxNavigationControllerDelegateProxy<UINavigationController>.self)
23+
return DelegateProxyFactory.sharedFactory(for: RxNavigationControllerDelegateProxy.self)
2424
}
2525

2626
/// For more information take a look at `DelegateProxyType`.

RxCocoa/iOS/Proxies/RxPickerViewDataSourceProxy.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ final fileprivate class PickerViewDataSourceNotSet: NSObject, UIPickerViewDataSo
2626
}
2727

2828
/// For more information take a look at `DelegateProxyType`.
29-
public class RxPickerViewDataSourceProxy<P: UIPickerView>
30-
: DelegateProxy<P, UIPickerViewDataSource>
29+
public class RxPickerViewDataSourceProxy
30+
: DelegateProxy<UIPickerView, UIPickerViewDataSource>
3131
, DelegateProxyType
3232
, UIPickerViewDataSource {
3333

3434
public static var factory: DelegateProxyFactory {
35-
return DelegateProxyFactory.sharedFactory(for: RxPickerViewDataSourceProxy<UIPickerView>.self)
35+
return DelegateProxyFactory.sharedFactory(for: RxPickerViewDataSourceProxy.self)
3636
}
3737

3838
/// Typed parent object.
@@ -42,7 +42,7 @@ public class RxPickerViewDataSourceProxy<P: UIPickerView>
4242
/// Initializes `RxPickerViewDataSourceProxy`
4343
///
4444
/// - parameter parentObject: Parent object for delegate proxy.
45-
public required init(parentObject: P) {
45+
public required init(parentObject: UIPickerView) {
4646
self.pickerView = parentObject
4747
super.init(parentObject: parentObject)
4848
}
@@ -67,12 +67,12 @@ public class RxPickerViewDataSourceProxy<P: UIPickerView>
6767
}
6868

6969
/// For more information take a look at `DelegateProxyType`.
70-
public override class func setCurrentDelegate(_ delegate: UIPickerViewDataSource?, toObject object: P) {
70+
public override class func setCurrentDelegate(_ delegate: UIPickerViewDataSource?, toObject object: UIPickerView) {
7171
object.dataSource = delegate
7272
}
7373

7474
/// For more information take a look at `DelegateProxyType`.
75-
public override class func currentDelegate(for object: P) -> UIPickerViewDataSource? {
75+
public override class func currentDelegate(for object: UIPickerView) -> UIPickerViewDataSource? {
7676
return object.dataSource
7777
}
7878

RxCocoa/iOS/Proxies/RxPickerViewDelegateProxy.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
#endif
1414
import UIKit
1515

16-
open class RxPickerViewDelegateProxy<P: UIPickerView>
17-
: DelegateProxy<P, UIPickerViewDelegate>
16+
open class RxPickerViewDelegateProxy
17+
: DelegateProxy<UIPickerView, UIPickerViewDelegate>
1818
, DelegateProxyType
1919
, UIPickerViewDelegate {
2020

2121
public static var factory: DelegateProxyFactory {
22-
return DelegateProxyFactory.sharedFactory(for: RxPickerViewDelegateProxy<UIPickerView>.self)
22+
return DelegateProxyFactory.sharedFactory(for: RxPickerViewDelegateProxy.self)
2323
}
2424

2525
/// For more information take a look at `DelegateProxyType`.

RxCocoa/iOS/Proxies/RxScrollViewDelegateProxy.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ import RxSwift
1414
import UIKit
1515

1616
/// For more information take a look at `DelegateProxyType`.
17-
open class RxScrollViewDelegateProxy<P: UIScrollView>
18-
: DelegateProxy<P, UIScrollViewDelegate>
17+
open class RxScrollViewDelegateProxy
18+
: DelegateProxy<UIScrollView, UIScrollViewDelegate>
1919
, DelegateProxyType
2020
, UIScrollViewDelegate {
2121

2222
public static var factory: DelegateProxyFactory {
23-
return DelegateProxyFactory.sharedFactory(for: RxScrollViewDelegateProxy<UIScrollView>.self)
23+
return DelegateProxyFactory.sharedFactory(for: RxScrollViewDelegateProxy.self)
2424
}
2525

2626
public static func knownImplementations() {
27-
RxTableViewDelegateProxy<UITableView>.register()
28-
RxCollectionViewDelegateProxy<UICollectionView>.register()
29-
RxTextViewDelegateProxy<UITextView>.register()
27+
RxTableViewDelegateProxy.register(for: UITableView.self)
28+
RxCollectionViewDelegateProxy.register(for: UICollectionView.self)
29+
RxTextViewDelegateProxy.register(for: UITextView.self)
3030
}
3131

3232
fileprivate var _contentOffsetBehaviorSubject: BehaviorSubject<CGPoint>?

RxCocoa/iOS/Proxies/RxSearchBarDelegateProxy.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import RxSwift
1414
#endif
1515

1616
/// For more information take a look at `DelegateProxyType`.
17-
open class RxSearchBarDelegateProxy<P: UISearchBar>
18-
: DelegateProxy<P, UISearchBarDelegate>
17+
open class RxSearchBarDelegateProxy
18+
: DelegateProxy<UISearchBar, UISearchBarDelegate>
1919
, DelegateProxyType
2020
, UISearchBarDelegate {
2121

2222
// MARK: Delegate proxy methods
2323

2424
public static var factory: DelegateProxyFactory {
25-
return DelegateProxyFactory.sharedFactory(for: RxSearchBarDelegateProxy<UISearchBar>.self)
25+
return DelegateProxyFactory.sharedFactory(for: RxSearchBarDelegateProxy.self)
2626
}
2727

2828
/// For more information take a look at `DelegateProxyType`.

RxCocoa/iOS/Proxies/RxSearchControllerDelegateProxy.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515

1616
/// For more information take a look at `DelegateProxyType`.
1717
@available(iOS 8.0, *)
18-
open class RxSearchControllerDelegateProxy<P: UISearchController>
19-
: DelegateProxy<P, UISearchControllerDelegate>
18+
open class RxSearchControllerDelegateProxy
19+
: DelegateProxy<UISearchController, UISearchControllerDelegate>
2020
, DelegateProxyType
2121
, UISearchControllerDelegate {
2222

2323
public static var factory: DelegateProxyFactory {
24-
return DelegateProxyFactory.sharedFactory(for: RxSearchControllerDelegateProxy<UISearchController>.self)
24+
return DelegateProxyFactory.sharedFactory(for: RxSearchControllerDelegateProxy.self)
2525
}
2626

2727
/// For more information take a look at `DelegateProxyType`.

RxCocoa/iOS/Proxies/RxTabBarControllerDelegateProxy.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import RxSwift
1414
#endif
1515

1616
/// For more information take a look at `DelegateProxyType`.
17-
open class RxTabBarControllerDelegateProxy<P: UITabBarController>
18-
: DelegateProxy<P, UITabBarControllerDelegate>
17+
open class RxTabBarControllerDelegateProxy
18+
: DelegateProxy<UITabBarController, UITabBarControllerDelegate>
1919
, DelegateProxyType
2020
, UITabBarControllerDelegate {
2121

2222
public static var factory: DelegateProxyFactory {
23-
return DelegateProxyFactory.sharedFactory(for: RxTabBarControllerDelegateProxy<UITabBarController>.self)
23+
return DelegateProxyFactory.sharedFactory(for: RxTabBarControllerDelegateProxy.self)
2424
}
2525

2626
/// For more information take a look at `DelegateProxyType`.

RxCocoa/iOS/Proxies/RxTabBarDelegateProxy.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import RxSwift
1414
#endif
1515

1616
/// For more information take a look at `DelegateProxyType`.
17-
open class RxTabBarDelegateProxy<P: UITabBar>
18-
: DelegateProxy<P, UITabBarDelegate>
17+
open class RxTabBarDelegateProxy
18+
: DelegateProxy<UITabBar, UITabBarDelegate>
1919
, DelegateProxyType
2020
, UITabBarDelegate {
2121

2222
public static var factory: DelegateProxyFactory {
23-
return DelegateProxyFactory.sharedFactory(for: RxTabBarDelegateProxy<UITabBar>.self)
23+
return DelegateProxyFactory.sharedFactory(for: RxTabBarDelegateProxy.self)
2424
}
2525

2626
/// For more information take a look at `DelegateProxyType`.

RxCocoa/iOS/Proxies/RxTableViewDataSourceProxy.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ final class TableViewDataSourceNotSet
2929
}
3030

3131
/// For more information take a look at `DelegateProxyType`.
32-
open class RxTableViewDataSourceProxy<P: UITableView>
33-
: DelegateProxy<P, UITableViewDataSource>
32+
open class RxTableViewDataSourceProxy
33+
: DelegateProxy<UITableView, UITableViewDataSource>
3434
, DelegateProxyType
3535
, UITableViewDataSource {
3636

3737
public static var factory: DelegateProxyFactory {
38-
return DelegateProxyFactory.sharedFactory(for: RxTableViewDataSourceProxy<UITableView>.self)
38+
return DelegateProxyFactory.sharedFactory(for: RxTableViewDataSourceProxy.self)
3939
}
4040

4141
/// Typed parent object.

0 commit comments

Comments
 (0)