Skip to content

Commit eccd8cc

Browse files
committed
Merge branch 'sergdort-feature/reactive-uipickerview' into develop
2 parents 42d4250 + 3afb0e7 commit eccd8cc

18 files changed

+1109
-25
lines changed

.jazzy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ custom_categories:
198198
- name: RxCocoa/iOS/DataSources
199199
children:
200200
- RxCollectionViewReactiveArrayDataSource
201+
- RxPickerViewAdapter
201202
- RxTableViewReactiveArrayDataSource
202203
- name: RxCocoa/iOS/Events
203204
children:
@@ -241,12 +242,14 @@ custom_categories:
241242
- name: RxCocoa/iOS/Protocols
242243
children:
243244
- RxCollectionViewDataSourceType
245+
- RxPickerViewDataSourceType
244246
- RxTableViewDataSourceType
245247
- name: RxCocoa/iOS/Proxies
246248
children:
247249
- RxCollectionViewDataSourceProxy
248250
- RxCollectionViewDelegateProxy
249251
- RxNavigationControllerDelegateProxy
252+
- RxPickerViewDataSourceProxy
250253
- RxPickerViewDelegateProxy
251254
- RxScrollViewDelegateProxy
252255
- RxSearchBarDelegateProxy

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ All notable changes to this project will be documented in this file.
1313
* Adds `willDisplaySupplementaryView` to `UICollectionView`
1414
* Adds `didEndDisplayingSupplementaryView` to `UICollectionView`
1515

16+
## [3.6.0]()
17+
18+
* Adds `RxPickerViewDataSourceType`
19+
* Adds `UIPickerView` extensions:
20+
* `modelSelected`
21+
* `itemTitles`
22+
* `itemAttributedTitles`
23+
* `items`
24+
1625
#### Anomalies
1726

1827
## [3.5.0](https://github.com/ReactiveX/RxSwift/releases/tag/3.5.0)

Rx.xcodeproj/project.pbxproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@
7878
9BA1CBFD1C0F84A10044B50A /* UIActivityIndicatorView+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BA1CBD11C0F7C0A0044B50A /* UIActivityIndicatorView+Rx.swift */; };
7979
9BA1CBFE1C0F84C40044B50A /* UIActivityIndicatorView+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BA1CBD11C0F7C0A0044B50A /* UIActivityIndicatorView+Rx.swift */; };
8080
9D71C4D21BF08191006E8F59 /* UIButton+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = C88254061B8A752B00B02D69 /* UIButton+Rx.swift */; };
81+
A520FFF71F0D258E00573734 /* RxPickerViewDataSourceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A520FFF61F0D258E00573734 /* RxPickerViewDataSourceType.swift */; };
82+
A520FFF81F0D258E00573734 /* RxPickerViewDataSourceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A520FFF61F0D258E00573734 /* RxPickerViewDataSourceType.swift */; };
83+
A520FFF91F0D258E00573734 /* RxPickerViewDataSourceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A520FFF61F0D258E00573734 /* RxPickerViewDataSourceType.swift */; };
84+
A520FFFA1F0D258E00573734 /* RxPickerViewDataSourceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A520FFF61F0D258E00573734 /* RxPickerViewDataSourceType.swift */; };
85+
A520FFFC1F0D291500573734 /* RxPickerViewDataSourceProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = A520FFFB1F0D291500573734 /* RxPickerViewDataSourceProxy.swift */; };
86+
A520FFFD1F0D291500573734 /* RxPickerViewDataSourceProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = A520FFFB1F0D291500573734 /* RxPickerViewDataSourceProxy.swift */; };
87+
A520FFFE1F0D291500573734 /* RxPickerViewDataSourceProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = A520FFFB1F0D291500573734 /* RxPickerViewDataSourceProxy.swift */; };
88+
A520FFFF1F0D291500573734 /* RxPickerViewDataSourceProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = A520FFFB1F0D291500573734 /* RxPickerViewDataSourceProxy.swift */; };
89+
A5CD038A1F1660F40005A376 /* RxPickerViewAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5CD03891F1660F40005A376 /* RxPickerViewAdapter.swift */; };
90+
A5CD038C1F1660F40005A376 /* RxPickerViewAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5CD03891F1660F40005A376 /* RxPickerViewAdapter.swift */; };
91+
A5CD038D1F1660F40005A376 /* RxPickerViewAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5CD03891F1660F40005A376 /* RxPickerViewAdapter.swift */; };
8192
AAE623761C82475700FC7801 /* UIProgressView+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE623751C82475700FC7801 /* UIProgressView+Rx.swift */; };
8293
AAE623771C82475700FC7801 /* UIProgressView+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE623751C82475700FC7801 /* UIProgressView+Rx.swift */; };
8394
B44D73EC1EE6D4A300EBFBE8 /* UIViewController+RxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 271A97421CFC99FE00D64125 /* UIViewController+RxTests.swift */; };
@@ -1701,6 +1712,9 @@
17011712
91BE429B1CBF7EC000F6B062 /* UIPageControl+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIPageControl+Rx.swift"; sourceTree = "<group>"; };
17021713
9BA1CBD11C0F7C0A0044B50A /* UIActivityIndicatorView+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIActivityIndicatorView+Rx.swift"; sourceTree = "<group>"; };
17031714
A111CE961B91C97C00D0DCEE /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
1715+
A520FFF61F0D258E00573734 /* RxPickerViewDataSourceType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxPickerViewDataSourceType.swift; sourceTree = "<group>"; };
1716+
A520FFFB1F0D291500573734 /* RxPickerViewDataSourceProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxPickerViewDataSourceProxy.swift; sourceTree = "<group>"; };
1717+
A5CD03891F1660F40005A376 /* RxPickerViewAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxPickerViewAdapter.swift; sourceTree = "<group>"; };
17041718
AAE623751C82475700FC7801 /* UIProgressView+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIProgressView+Rx.swift"; sourceTree = "<group>"; };
17051719
C809396D1B8A71760088E94D /* RxCocoa.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxCocoa.framework; sourceTree = BUILT_PRODUCTS_DIR; };
17061720
C80939E71B8A71840088E94D /* RxCocoa.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxCocoa.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -2921,6 +2935,7 @@
29212935
children = (
29222936
C88253F11B8A752B00B02D69 /* RxCollectionViewReactiveArrayDataSource.swift */,
29232937
C88253F21B8A752B00B02D69 /* RxTableViewReactiveArrayDataSource.swift */,
2938+
A5CD03891F1660F40005A376 /* RxPickerViewAdapter.swift */,
29242939
);
29252940
path = DataSources;
29262941
sourceTree = "<group>";
@@ -2938,6 +2953,7 @@
29382953
children = (
29392954
C88253F71B8A752B00B02D69 /* RxCollectionViewDataSourceType.swift */,
29402955
C88253F81B8A752B00B02D69 /* RxTableViewDataSourceType.swift */,
2956+
A520FFF61F0D258E00573734 /* RxPickerViewDataSourceType.swift */,
29412957
);
29422958
path = Protocols;
29432959
sourceTree = "<group>";
@@ -2959,6 +2975,7 @@
29592975
844BC8AA1CE4FA5600F5C7CB /* RxPickerViewDelegateProxy.swift */,
29602976
D9080ACD1EA05A16002B433B /* RxNavigationControllerDelegateProxy.swift */,
29612977
4613457B1D9A4AEE001ABAF2 /* RxWebViewDelegateProxy.swift */,
2978+
A520FFFB1F0D291500573734 /* RxPickerViewDataSourceProxy.swift */,
29622979
);
29632980
path = Proxies;
29642981
sourceTree = "<group>";
@@ -3991,6 +4008,7 @@
39914008
F31F35B01BB4FED800961002 /* UIStepper+Rx.swift in Sources */,
39924009
C89AB1C61DAAC3350065FBE6 /* ControlEvent.swift in Sources */,
39934010
C882542D1B8A752B00B02D69 /* UIImageView+Rx.swift in Sources */,
4011+
A520FFFC1F0D291500573734 /* RxPickerViewDataSourceProxy.swift in Sources */,
39944012
C882542A1B8A752B00B02D69 /* UIControl+Rx.swift in Sources */,
39954013
C8D132441C42D15E00B59FFF /* SectionedViewDataSourceType.swift in Sources */,
39964014
C89AB1FA1DAAC3350065FBE6 /* Variable+SharedSequence.swift in Sources */,
@@ -4011,6 +4029,7 @@
40114029
54D2138E1CE0824E0028D5B4 /* UINavigationItem+Rx.swift in Sources */,
40124030
91BE429C1CBF7EC000F6B062 /* UIPageControl+Rx.swift in Sources */,
40134031
C88254211B8A752B00B02D69 /* RxSearchBarDelegateProxy.swift in Sources */,
4032+
A520FFF71F0D258E00573734 /* RxPickerViewDataSourceType.swift in Sources */,
40144033
7EDBAEBC1C89B9B7006CBE67 /* UITabBarItem+Rx.swift in Sources */,
40154034
C839365F1C70E02200A9A09E /* UIApplication+Rx.swift in Sources */,
40164035
844BC8AC1CE4FA6300F5C7CB /* RxPickerViewDelegateProxy.swift in Sources */,
@@ -4020,6 +4039,7 @@
40204039
ECBBA59B1DF8C0BA00DDDC2E /* UITabBarController+Rx.swift in Sources */,
40214040
C89AB21A1DAAC3350065FBE6 /* NSObject+Rx+RawRepresentable.swift in Sources */,
40224041
C8BCD3ED1C14B5FB005F1280 /* UIView+Rx.swift in Sources */,
4042+
A5CD038A1F1660F40005A376 /* RxPickerViewAdapter.swift in Sources */,
40234043
C89AB2021DAAC3350065FBE6 /* KVORepresentable+CoreGraphics.swift in Sources */,
40244044
C80D338F1B91EF9E0014629D /* Observable+Bind.swift in Sources */,
40254045
C81772981E7F408100EA679B /* Deprecated.swift in Sources */,
@@ -4080,6 +4100,7 @@
40804100
C89AB1FF1DAAC3350065FBE6 /* UIBindingObserver.swift in Sources */,
40814101
C8093EE41B8A732E0088E94D /* DelegateProxyType.swift in Sources */,
40824102
C86781AB1DB823B500B2029A /* NSTextField+Rx.swift in Sources */,
4103+
A520FFF81F0D258E00573734 /* RxPickerViewDataSourceType.swift in Sources */,
40834104
C89AB1E31DAAC3350065FBE6 /* Variable+Driver.swift in Sources */,
40844105
C89AB1D31DAAC3350065FBE6 /* ControlProperty+Driver.swift in Sources */,
40854106
C8A81CA11E05E82C0008DEF4 /* DispatchQueue+Extensions.swift in Sources */,
@@ -4089,6 +4110,7 @@
40894110
C89AB2511DAAC3A60065FBE6 /* _RXObjCRuntime.m in Sources */,
40904111
C89AB20B1DAAC3350065FBE6 /* KVORepresentable.swift in Sources */,
40914112
C89AB1A71DAAC25A0065FBE6 /* RxCocoaObjCRuntimeError+Extensions.swift in Sources */,
4113+
A520FFFD1F0D291500573734 /* RxPickerViewDataSourceProxy.swift in Sources */,
40924114
C89AB2411DAAC3A60065FBE6 /* _RXDelegateProxy.m in Sources */,
40934115
C89AB1FB1DAAC3350065FBE6 /* Variable+SharedSequence.swift in Sources */,
40944116
C867819C1DB823B500B2029A /* NSControl+Rx.swift in Sources */,
@@ -5178,6 +5200,7 @@
51785200
C89AB23B1DAAC3A60065FBE6 /* _RX.m in Sources */,
51795201
C8F0C0151BBBFBB9001B112F /* UIControl+Rx.swift in Sources */,
51805202
C8A81CA31E05E82C0008DEF4 /* DispatchQueue+Extensions.swift in Sources */,
5203+
A520FFFA1F0D258E00573734 /* RxPickerViewDataSourceType.swift in Sources */,
51815204
C8D132471C42D15E00B59FFF /* SectionedViewDataSourceType.swift in Sources */,
51825205
C8F0C0161BBBFBB9001B112F /* UITableView+Rx.swift in Sources */,
51835206
C89AB1D11DAAC3350065FBE6 /* ControlEvent+Driver.swift in Sources */,
@@ -5201,6 +5224,7 @@
52015224
C8F0C01F1BBBFBB9001B112F /* Observable+Bind.swift in Sources */,
52025225
C8F0C0201BBBFBB9001B112F /* UISegmentedControl+Rx.swift in Sources */,
52035226
C89AB1ED1DAAC3350065FBE6 /* SharedSequence+Operators+arity.swift in Sources */,
5227+
A520FFFF1F0D291500573734 /* RxPickerViewDataSourceProxy.swift in Sources */,
52045228
C8F0C0221BBBFBB9001B112F /* UIButton+Rx.swift in Sources */,
52055229
9BA1CBFE1C0F84C40044B50A /* UIActivityIndicatorView+Rx.swift in Sources */,
52065230
C89AB1A91DAAC25A0065FBE6 /* RxCocoaObjCRuntimeError+Extensions.swift in Sources */,
@@ -5229,6 +5253,7 @@
52295253
C89AB1761DAAC1680065FBE6 /* ControlTarget.swift in Sources */,
52305254
D9080AD61EA05DEC002B433B /* UINavigationController+Rx.swift in Sources */,
52315255
C89AB21D1DAAC3350065FBE6 /* NSObject+Rx+RawRepresentable.swift in Sources */,
5256+
A5CD038D1F1660F40005A376 /* RxPickerViewAdapter.swift in Sources */,
52325257
C89AB2191DAAC3350065FBE6 /* NSObject+Rx+KVORepresentable.swift in Sources */,
52335258
C89AB2531DAAC3A60065FBE6 /* _RXObjCRuntime.m in Sources */,
52345259
C8F0C0381BBBFBB9001B112F /* UITextField+Rx.swift in Sources */,
@@ -5294,6 +5319,7 @@
52945319
C89AB2201DAAC3350065FBE6 /* NSObject+Rx.swift in Sources */,
52955320
C8D132461C42D15E00B59FFF /* SectionedViewDataSourceType.swift in Sources */,
52965321
D203C4F31BB9C4CA00D02D00 /* RxCollectionViewReactiveArrayDataSource.swift in Sources */,
5322+
A5CD038C1F1660F40005A376 /* RxPickerViewAdapter.swift in Sources */,
52975323
D203C50B1BB9C53E00D02D00 /* UIScrollView+Rx.swift in Sources */,
52985324
C89AB1E81DAAC3350065FBE6 /* ObservableConvertibleType+SharedSequence.swift in Sources */,
52995325
C89AB1A81DAAC25A0065FBE6 /* RxCocoaObjCRuntimeError+Extensions.swift in Sources */,
@@ -5325,6 +5351,7 @@
53255351
ECBBA59F1DF8C0D400DDDC2E /* RxTabBarControllerDelegateProxy.swift in Sources */,
53265352
842A5A2D1C357F93003568D5 /* NSTextStorage+Rx.swift in Sources */,
53275353
D203C5071BB9C53E00D02D00 /* UIDatePicker+Rx.swift in Sources */,
5354+
A520FFFE1F0D291500573734 /* RxPickerViewDataSourceProxy.swift in Sources */,
53285355
C89AB1E01DAAC3350065FBE6 /* ObservableConvertibleType+Driver.swift in Sources */,
53295356
C89AB2241DAAC3350065FBE6 /* URLSession+Rx.swift in Sources */,
53305357
D203C50D1BB9C53E00D02D00 /* UISegmentedControl+Rx.swift in Sources */,
@@ -5336,6 +5363,7 @@
53365363
D203C50A1BB9C53E00D02D00 /* UILabel+Rx.swift in Sources */,
53375364
C89AB1FC1DAAC3350065FBE6 /* Variable+SharedSequence.swift in Sources */,
53385365
D203C4F51BB9C52900D02D00 /* ItemEvents.swift in Sources */,
5366+
A520FFF91F0D258E00573734 /* RxPickerViewDataSourceType.swift in Sources */,
53395367
C8BCD3F61C14B6D1005F1280 /* NSLayoutConstraint+Rx.swift in Sources */,
53405368
D203C4FA1BB9C53700D02D00 /* RxCollectionViewDataSourceProxy.swift in Sources */,
53415369
C89AB2141DAAC3350065FBE6 /* NotificationCenter+Rx.swift in Sources */,
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//
2+
// RxPickerViewAdapter.swift
3+
// RxCocoa
4+
//
5+
// Created by Sergey Shulga on 12/07/2017.
6+
// Copyright © 2017 Krunoslav Zaher. All rights reserved.
7+
//
8+
9+
#if os(iOS)
10+
import UIKit
11+
#if !RX_NO_MODULE
12+
import RxSwift
13+
#endif
14+
15+
private class RxPickerViewArrayDataSource<T>: NSObject, UIPickerViewDataSource, SectionedViewDataSourceType {
16+
fileprivate var items: [T] = []
17+
18+
func model(at indexPath: IndexPath) throws -> Any {
19+
guard items.indices ~= indexPath.row else {
20+
throw RxCocoaError.itemsNotYetBound(object: self)
21+
}
22+
return items[indexPath.row]
23+
}
24+
25+
func numberOfComponents(in pickerView: UIPickerView) -> Int {
26+
return 1
27+
}
28+
29+
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
30+
return items.count
31+
}
32+
}
33+
34+
private class RxPickerViewSequenceDataSource<S: Sequence>
35+
: RxPickerViewArrayDataSource<S.Iterator.Element>
36+
, RxPickerViewDataSourceType {
37+
typealias Element = S
38+
39+
func pickerView(_ pickerView: UIPickerView, observedEvent: Event<S>) {
40+
UIBindingObserver(UIElement: self) { dataSource, items in
41+
dataSource.items = items
42+
pickerView.reloadAllComponents()
43+
}
44+
.on(observedEvent.map(Array.init))
45+
}
46+
}
47+
48+
final class RxStringPickerViewAdapter<S: Sequence>
49+
: RxPickerViewSequenceDataSource<S>
50+
, UIPickerViewDelegate {
51+
52+
typealias TitleForRow = (Int, S.Iterator.Element) -> String?
53+
private let titleForRow: TitleForRow
54+
55+
init(titleForRow: @escaping TitleForRow) {
56+
self.titleForRow = titleForRow
57+
super.init()
58+
}
59+
60+
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
61+
return titleForRow(row, items[row])
62+
}
63+
}
64+
65+
final class RxAttributedStringPickerViewAdapter<S: Sequence>: RxPickerViewSequenceDataSource<S>, UIPickerViewDelegate {
66+
typealias AttributedTitleForRow = (Int, S.Iterator.Element) -> NSAttributedString?
67+
private let attributedTitleForRow: AttributedTitleForRow
68+
69+
init(attributedTitleForRow: @escaping AttributedTitleForRow) {
70+
self.attributedTitleForRow = attributedTitleForRow
71+
super.init()
72+
}
73+
74+
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
75+
return attributedTitleForRow(row, items[row])
76+
}
77+
}
78+
79+
final class RxPickerViewAdapter<S: Sequence>: RxPickerViewSequenceDataSource<S>, UIPickerViewDelegate {
80+
typealias ViewForRow = (Int, S.Iterator.Element, UIView?) -> UIView
81+
private let viewForRow: ViewForRow
82+
83+
init(viewForRow: @escaping ViewForRow) {
84+
self.viewForRow = viewForRow
85+
super.init()
86+
}
87+
88+
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
89+
return viewForRow(row, items[row], view)
90+
}
91+
}
92+
93+
#endif
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// RxPickerViewDataSourceType.swift
3+
// RxCocoa
4+
//
5+
// Created by Sergey Shulga on 05/07/2017.
6+
// Copyright © 2017 Krunoslav Zaher. All rights reserved.
7+
//
8+
9+
#if os(iOS)
10+
11+
import UIKit
12+
#if !RX_NO_MODULE
13+
import RxSwift
14+
#endif
15+
16+
/// Marks data source as `UIPickerView` reactive data source enabling it to be used with one of the `bindTo` methods.
17+
public protocol RxPickerViewDataSourceType {
18+
/// Type of elements that can be bound to picker view.
19+
associatedtype Element
20+
21+
/// New observable sequence event observed.
22+
///
23+
/// - parameter pickerView: Bound picker view.
24+
/// - parameter observedEvent: Event
25+
func pickerView(_ pickerView: UIPickerView, observedEvent: Event<Element>)
26+
}
27+
28+
#endif
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//
2+
// RxPickerViewDataSourceProxy.swift
3+
// RxCocoa
4+
//
5+
// Created by Sergey Shulga on 05/07/2017.
6+
// Copyright © 2017 Krunoslav Zaher. All rights reserved.
7+
//
8+
9+
#if os(iOS)
10+
11+
import UIKit
12+
#if !RX_NO_MODULE
13+
import RxSwift
14+
#endif
15+
16+
fileprivate let pickerViewDataSourceNotSet = PickerViewDataSourceNotSet()
17+
18+
final fileprivate class PickerViewDataSourceNotSet: NSObject, UIPickerViewDataSource {
19+
func numberOfComponents(in pickerView: UIPickerView) -> Int {
20+
return 0
21+
}
22+
23+
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
24+
return 0
25+
}
26+
}
27+
28+
/// For more information take a look at `DelegateProxyType`.
29+
public class RxPickerViewDataSourceProxy
30+
: DelegateProxy
31+
, UIPickerViewDataSource
32+
, DelegateProxyType {
33+
34+
/// Typed parent object.
35+
public weak fileprivate(set) var pickerView: UIPickerView?
36+
private weak var _requiredMethodsDataSource: UIPickerViewDataSource? = pickerViewDataSourceNotSet
37+
38+
/// Initializes `RxPickerViewDataSourceProxy`
39+
///
40+
/// - parameter parentObject: Parent object for delegate proxy.
41+
public required init(parentObject: AnyObject) {
42+
self.pickerView = castOrFatalError(parentObject)
43+
super.init(parentObject: parentObject)
44+
}
45+
46+
47+
// MARK: UIPickerViewDataSource
48+
49+
/// Required delegate method implementation.
50+
public func numberOfComponents(in pickerView: UIPickerView) -> Int {
51+
return (_requiredMethodsDataSource ?? pickerViewDataSourceNotSet).numberOfComponents(in: pickerView)
52+
}
53+
54+
/// Required delegate method implementation.
55+
public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
56+
return (_requiredMethodsDataSource ?? pickerViewDataSourceNotSet).pickerView(pickerView, numberOfRowsInComponent: component)
57+
}
58+
59+
// MARK: proxy
60+
61+
/// For more information take a look at `DelegateProxyType`.
62+
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
63+
let pickerView: UIPickerView = castOrFatalError(object)
64+
return pickerView.createRxDataSourceProxy()
65+
}
66+
67+
/// For more information take a look at `DelegateProxyType`.
68+
public override class func delegateAssociatedObjectTag() -> UnsafeRawPointer {
69+
return dataSourceAssociatedTag
70+
}
71+
72+
/// For more information take a look at `DelegateProxyType`.
73+
public class func setCurrentDelegate(_ delegate: AnyObject?, toObject object: AnyObject) {
74+
let pickerView: UIPickerView = castOrFatalError(object)
75+
pickerView.dataSource = castOptionalOrFatalError(delegate)
76+
}
77+
78+
/// For more information take a look at `DelegateProxyType`.
79+
public class func currentDelegateFor(_ object: AnyObject) -> AnyObject? {
80+
let pickerView: UIPickerView = castOrFatalError(object)
81+
return pickerView.dataSource
82+
}
83+
84+
/// For more information take a look at `DelegateProxyType`.
85+
public override func setForwardToDelegate(_ forwardToDelegate: AnyObject?, retainDelegate: Bool) {
86+
let requiredMethodsDataSource: UIPickerViewDataSource? = castOptionalOrFatalError(forwardToDelegate)
87+
_requiredMethodsDataSource = requiredMethodsDataSource ?? pickerViewDataSourceNotSet
88+
super.setForwardToDelegate(forwardToDelegate, retainDelegate: retainDelegate)
89+
}
90+
}
91+
92+
#endif

0 commit comments

Comments
 (0)