API

RxSwift支持的操作符

有时候,同一个操作符会有多个别名,不同平台或实现有时也会让同一个操作符有不同的名字。有的是历史原因,或者撞上了语言的关键字。

当缺乏社区强烈共识前,RxSwift操作符通常包含多个别名。

操作符默认是无状态的。

创建 Observables

变换操作

过滤操作

结合操作

错误处理

辅助操作

条件和布尔操作

算数和聚合操作

连接操作

创建新的操作符同样也很简单。

RxCocoa extensions

iOS / OSX

2. extension NSObject {

4. public var rx_deallocated: Observable<Void> {}

6. #if !DISABLE_SWIZZLING

8. public var rx_deallocating: Observable<Void> {}

10. #endif

12. }
1. extension NSObject {

3. public func rx_observe<Element>(
4. type: E.Type,
5. _ keyPath: String,
6. options: NSKeyValueObservingOptions = .New | .Initial,
7. retainSelf: Bool = true
8. )  -> Observable<Element?> {}

10. #if !DISABLE_SWIZZLING

12. public func rx_observeWeakly<Element>(
13. type: E.Type,
14. _ keyPath: String,
15. options: NSKeyValueObservingOptions = .New | .Initial
16. ) -> Observable<Element?> {}

18. #endif
19. }
1. extension NSURLSession {

3. public func rx_response(request: NSURLRequest) -> Observable<(NSData, NSURLResponse)> {}

5. public func rx_data(request: NSURLRequest) -> Observable<NSData> {}

7. public func rx_JSON(request: NSURLRequest) -> Observable<AnyObject> {}

9. public func rx_JSON(URL: NSURL) -> Observable<AnyObject> {}

11. }
1. extension NSNotificationCenter {

3. public func rx_notification(name: String, object: AnyObject?) -> Observable<NSNotification> {}

5. }
1. class DelegateProxy {

3. public func observe(selector: Selector) -> Observable<[AnyObject]> {}

5. }
1. extension CLLocationManager {

3. public var rx_delegate: DelegateProxy {}

5. public var rx_didUpdateLocations: Observable<[CLLocation]> {}

7. public var rx_didFailWithError: Observable<NSError> {}

9. public var rx_didFinishDeferredUpdatesWithError: Observable<NSError> {}

11. public var rx_didPauseLocationUpdates: Observable<Void> {}

13. public var rx_didResumeLocationUpdates: Observable<Void> {}

15. public var rx_didUpdateHeading: Observable<CLHeading> {}

17. public var rx_didEnterRegion: Observable<CLRegion> {}

19. public var rx_didExitRegion: Observable<CLRegion> {}

21. public var rx_didDetermineStateForRegion: Observable<(state: CLRegionState, region: CLRegion)> {}

23. public var rx_monitoringDidFailForRegionWithError: Observable<(region: CLRegion?, error: NSError)> {}

25. public var rx_didStartMonitoringForRegion: Observable<CLRegion> {}

27. public var rx_didRangeBeaconsInRegion: Observable<(beacons: [CLBeacon], region: CLBeaconRegion)> {}

29. public var rx_rangingBeaconsDidFailForRegionWithError: Observable<(region: CLBeaconRegion, error: NSError)> {}

31. public var rx_didVisit: Observable<CLVisit> {}

33. public var rx_didChangeAuthorizationStatus: Observable<CLAuthorizationStatus> {}

35. }

iOS

2. extension UIControl {

4. public func rx_controlEvent(controlEvents: UIControlEvents) -> ControlEvent<Void> {}

6. public var rx_enabled: ObserverOf<Bool> {}
7. }
1. extension UIButton {

3. public var rx_tap: ControlEvent<Void> {}

5. }
1. extension UITextField {

3. public var rx_text: ControlProperty<String> {}

5. }
1. extension UITextView {

3. override func rx_createDelegateProxy() -> RxScrollViewDelegateProxy {}

5. public var rx_text: ControlProperty<String> {}

7. }
1. extension UISearchBar {

3. public var rx_delegate: DelegateProxy {}

5. public var rx_searchText: ControlProperty<String> {}

7. }
1. extension UILabel {

3. public var rx_text: ObserverOf<String> {}

5. }
1. extension UIDatePicker {

3. public var rx_date: ControlProperty<NSDate> {}

5. }
1. extension UIImageView {

3. public var rx_image: ObserverOf<UIImage!> {}

5. public func rx_imageAnimated(transitionType: String?) -> AnyObserver<UIImage?>

7. }
1. extension UIScrollView {

3. public var rx_delegate: DelegateProxy {}

5. public func rx_setDelegate(delegate: UIScrollViewDelegate) {}

7. public var rx_contentOffset: ControlProperty<CGPoint> {}

9. }
1. extension UIBarButtonItem {

3. public var rx_tap: ControlEvent<Void> {}

5. }
1. extension UISlider {

3. public var rx_value: ControlProperty<Float> {}

5. }
1. extension UITableView {

3. public var rx_dataSource: DelegateProxy {}

5. public func rx_setDataSource(dataSource: UITableViewDataSource) -> Disposable {}

7. public func rx_itemsWithCellFactory(source: O)(cellFactory: (UITableView, Int, S.Generator.Element) -> UITableViewCell) -> Disposable {}

9. public func rx_itemsWithCellIdentifier(cellIdentifier: String, cellType: Cell.Type = Cell.self)(source: O)(configureCell: (Int, S.Generator.Element, Cell) -> Void) -> Disposable {}

11. public func rx_itemsWithDataSource(dataSource: DataSource)(source: O) -> Disposable {}

13. public var rx_itemSelected: ControlEvent<NSIndexPath> {}

15. public var rx_itemDeselected: ControlEvent<NSIndexPath> {}

17. public var rx_itemInserted: ControlEvent<NSIndexPath> {}

19. public var rx_itemDeleted: ControlEvent<NSIndexPath> {}

21. public var rx_itemMoved: ControlEvent<ItemMovedEvent> {}

23. // This method only works in case one of the `rx_itemsWith*` methods was used, or data source implements `SectionedViewDataSourceType`
24. public func rx_modelSelected<T>(modelType: T.Type) -> ControlEvent<T> {}

26. // This method only works in case one of the `rx_itemsWith*` methods was used, or data source implements `SectionedViewDataSourceType`
27. public func rx_modelDeselected<T>(modelType: T.Type) -> ControlEvent<T> {}

29. }
1. extension UICollectionView {

3. public var rx_dataSource: DelegateProxy {}

5. public func rx_setDataSource(dataSource: UICollectionViewDataSource) -> Disposable {}

7. public func rx_itemsWithCellFactory(source: O)(cellFactory: (UICollectionView, Int, S.Generator.Element) -> UICollectionViewCell) -> Disposable {}

9. public func rx_itemsWithCellIdentifier(cellIdentifier: String, cellType: Cell.Type = Cell.self)(source: O)(configureCell: (Int, S.Generator.Element, Cell) -> Void) -> Disposable {}

11. public func rx_itemsWithDataSource(dataSource: DataSource)(source: O) -> Disposable {}

13. public var rx_itemSelected: ControlEvent<NSIndexPath> {}

15. public var rx_itemDeselected: ControlEvent<NSIndexPath> {}

17. // This method only works in case one of the `rx_itemsWith*` methods was used, or data source implements `SectionedViewDataSourceType`
18. public func rx_modelSelected<T>(modelType: T.Type) -> ControlEvent<T> {}

20. // This method only works in case one of the `rx_itemsWith*` methods was used, or data source implements `SectionedViewDataSourceType`
21. public func rx_modelSelected<T>(modelType: T.Type) -> ControlEvent<T> {}
22. }
1. extension UIGestureRecognizer {

3. public var rx_event: ControlEvent<UIGestureRecognizer> {}

5. }
1. extension UIImagePickerController {

3. public var rx_didFinishPickingMediaWithInfo: Observable<[String : AnyObject]> {}

5. public var rx_didCancel: Observable<()> {}

7. }
1. extension UISegmentedControl {

3. public var rx_value: ControlProperty<Int> {}

5. }
1. extension UISwitch {

3. public var rx_value: ControlProperty<Bool> {}

5. }
1. extension UIActivityIndicatorView {

3. public var rx_animating: AnyObserver<Bool> {}

5. }
1. extension UINavigationItem {

3. public var rx_title: AnyObserver<String?> {}
4. }

OSX

1. extension NSControl {

3. public var rx_controlEvent: ControlEvent<()> {}

5. public var rx_enabled: AnyObserver<Bool> {}

7. }
2. extension NSSlider {

4. public var rx_value: ControlProperty<Double> {}

6. }
1. extension NSButton {

3. public var rx_tap: ControlEvent<Void> {}

5. public var rx_state: ControlProperty<Int> {}

7. }
1. extension NSImageView {

3. public var rx_image: ObserverOf<NSImage?> {}

5. public func rx_imageAnimated(transitionType: String?) -> AnyObserver<NSImage?>
6. }
1. extension NSTextField {

3. public var rx_delegate: DelegateProxy {}

5. public var rx_text: ControlProperty<String> {}

7. }
1. extension UITabBarItem {

3. public var rx_badgeValue: AnyObserver<String?> {}

5. }