Update documentation (.md files)
This commit is contained in:
parent
cbb0ed5d29
commit
96ef70cc2f
|
|
@ -102,13 +102,13 @@ Creating new operators is also pretty straightforward.
|
|||
|
||||
```swift
|
||||
|
||||
extension NSObject {
|
||||
extension Reactive where Base: NSObject {
|
||||
|
||||
public var deallocated: Observable<Void> {}
|
||||
|
||||
#if !DISABLE_SWIZZLING
|
||||
|
||||
public var rx_deallocating: Observable<Void> {}
|
||||
public var deallocating: Observable<Void> {}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -118,9 +118,9 @@ extension NSObject {
|
|||
|
||||
|
||||
```swift
|
||||
extension NSObject {
|
||||
extension Reactive where Base: NSObject {
|
||||
|
||||
public func rx_observe<Element>(
|
||||
public func observe<Element>(
|
||||
type: E.Type,
|
||||
_ keyPath: String,
|
||||
options: NSKeyValueObservingOptions = .New | .Initial,
|
||||
|
|
@ -129,7 +129,7 @@ extension NSObject {
|
|||
|
||||
#if !DISABLE_SWIZZLING
|
||||
|
||||
public func rx_observeWeakly<Element>(
|
||||
public func observeWeakly<Element>(
|
||||
type: E.Type,
|
||||
_ keyPath: String,
|
||||
options: NSKeyValueObservingOptions = .New | .Initial
|
||||
|
|
@ -140,23 +140,23 @@ extension NSObject {
|
|||
```
|
||||
|
||||
```swift
|
||||
extension NSURLSession {
|
||||
extension Reactive where Base: NSURLSession {
|
||||
|
||||
public func rx_response(request: NSURLRequest) -> Observable<(NSData, NSURLResponse)> {}
|
||||
public func response(request: NSURLRequest) -> Observable<(NSData, NSURLResponse)> {}
|
||||
|
||||
public func rx_data(request: NSURLRequest) -> Observable<NSData> {}
|
||||
public func data(request: NSURLRequest) -> Observable<NSData> {}
|
||||
|
||||
public func rx_JSON(request: NSURLRequest) -> Observable<AnyObject> {}
|
||||
public func JSON(request: NSURLRequest) -> Observable<AnyObject> {}
|
||||
|
||||
public func rx_JSON(URL: NSURL) -> Observable<AnyObject> {}
|
||||
public func JSON(URL: NSURL) -> Observable<AnyObject> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension NSNotificationCenter {
|
||||
extension Reactive where Base: NSNotificationCenter {
|
||||
|
||||
public func rx_notification(name: String, object: AnyObject?) -> Observable<NSNotification> {}
|
||||
public func notification(name: String, object: AnyObject?) -> Observable<NSNotification> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
|
@ -170,39 +170,39 @@ class DelegateProxy {
|
|||
```
|
||||
|
||||
```swift
|
||||
extension CLLocationManager {
|
||||
extension Reactive where Base: CLLocationManager {
|
||||
|
||||
public var rx_delegate: DelegateProxy {}
|
||||
public var delegate: DelegateProxy {}
|
||||
|
||||
public var rx_didUpdateLocations: Observable<[CLLocation]> {}
|
||||
public var didUpdateLocations: Observable<[CLLocation]> {}
|
||||
|
||||
public var rx_didFailWithError: Observable<NSError> {}
|
||||
public var didFailWithError: Observable<NSError> {}
|
||||
|
||||
public var rx_didFinishDeferredUpdatesWithError: Observable<NSError> {}
|
||||
public var didFinishDeferredUpdatesWithError: Observable<NSError> {}
|
||||
|
||||
public var rx_didPauseLocationUpdates: Observable<Void> {}
|
||||
public var didPauseLocationUpdates: Observable<Void> {}
|
||||
|
||||
public var rx_didResumeLocationUpdates: Observable<Void> {}
|
||||
public var didResumeLocationUpdates: Observable<Void> {}
|
||||
|
||||
public var rx_didUpdateHeading: Observable<CLHeading> {}
|
||||
public var didUpdateHeading: Observable<CLHeading> {}
|
||||
|
||||
public var rx_didEnterRegion: Observable<CLRegion> {}
|
||||
public var didEnterRegion: Observable<CLRegion> {}
|
||||
|
||||
public var rx_didExitRegion: Observable<CLRegion> {}
|
||||
public var didExitRegion: Observable<CLRegion> {}
|
||||
|
||||
public var rx_didDetermineStateForRegion: Observable<(state: CLRegionState, region: CLRegion)> {}
|
||||
public var didDetermineStateForRegion: Observable<(state: CLRegionState, region: CLRegion)> {}
|
||||
|
||||
public var rx_monitoringDidFailForRegionWithError: Observable<(region: CLRegion?, error: NSError)> {}
|
||||
public var monitoringDidFailForRegionWithError: Observable<(region: CLRegion?, error: NSError)> {}
|
||||
|
||||
public var rx_didStartMonitoringForRegion: Observable<CLRegion> {}
|
||||
public var didStartMonitoringForRegion: Observable<CLRegion> {}
|
||||
|
||||
public var rx_didRangeBeaconsInRegion: Observable<(beacons: [CLBeacon], region: CLBeaconRegion)> {}
|
||||
public var didRangeBeaconsInRegion: Observable<(beacons: [CLBeacon], region: CLBeaconRegion)> {}
|
||||
|
||||
public var rx_rangingBeaconsDidFailForRegionWithError: Observable<(region: CLBeaconRegion, error: NSError)> {}
|
||||
public var rangingBeaconsDidFailForRegionWithError: Observable<(region: CLBeaconRegion, error: NSError)> {}
|
||||
|
||||
public var rx_didVisit: Observable<CLVisit> {}
|
||||
public var didVisit: Observable<CLVisit> {}
|
||||
|
||||
public var rx_didChangeAuthorizationStatus: Observable<CLAuthorizationStatus> {}
|
||||
public var didChangeAuthorizationStatus: Observable<CLAuthorizationStatus> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
|
@ -211,281 +211,281 @@ extension CLLocationManager {
|
|||
|
||||
```swift
|
||||
|
||||
extension UIControl {
|
||||
extension Reactive where Base: UIControl {
|
||||
|
||||
public func rx_controlEvent(controlEvents: UIControlEvents) -> ControlEvent<Void> {}
|
||||
public func controlEvent(controlEvents: UIControlEvents) -> ControlEvent<Void> {}
|
||||
|
||||
public var rx_enabled: ObserverOf<Bool> {}
|
||||
public var enabled: ObserverOf<Bool> {}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UIButton {
|
||||
extension Reactive where Base: UIButton {
|
||||
|
||||
public var rx_tap: ControlEvent<Void> {}
|
||||
public var tap: ControlEvent<Void> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UITextField {
|
||||
extension Reactive where Base: UITextField {
|
||||
|
||||
public var rx_text: ControlProperty<String> {}
|
||||
public var text: ControlProperty<String> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UITextView {
|
||||
extension Reactive where Base: UITextView {
|
||||
|
||||
override func rx_createDelegateProxy() -> RxScrollViewDelegateProxy {}
|
||||
override func createDelegateProxy() -> RxScrollViewDelegateProxy {}
|
||||
|
||||
public var rx_text: ControlProperty<String> {}
|
||||
public var text: ControlProperty<String> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UISearchBar {
|
||||
extension Reactive where Base: UISearchBar {
|
||||
|
||||
public var rx_delegate: DelegateProxy {}
|
||||
public var delegate: DelegateProxy {}
|
||||
|
||||
public var rx_searchText: ControlProperty<String> {}
|
||||
public var searchText: ControlProperty<String> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UILabel {
|
||||
extension Reactive where Base: UILabel {
|
||||
|
||||
public var rx_text: ObserverOf<String> {}
|
||||
public var text: ObserverOf<String> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UIDatePicker {
|
||||
extension Reactive where Base: UIDatePicker {
|
||||
|
||||
public var rx_date: ControlProperty<NSDate> {}
|
||||
public var date: ControlProperty<NSDate> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UIImageView {
|
||||
extension Reactive where Base: UIImageView {
|
||||
|
||||
public var rx_image: ObserverOf<UIImage!> {}
|
||||
public var image: ObserverOf<UIImage!> {}
|
||||
|
||||
public func rx_imageAnimated(transitionType: String?) -> AnyObserver<UIImage?>
|
||||
public func imageAnimated(transitionType: String?) -> AnyObserver<UIImage?>
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UIScrollView {
|
||||
extension Reactive where Base: UIScrollView {
|
||||
|
||||
public var rx_delegate: DelegateProxy {}
|
||||
public var delegate: DelegateProxy {}
|
||||
|
||||
public func rx_setDelegate(delegate: UIScrollViewDelegate) {}
|
||||
public func setDelegate(delegate: UIScrollViewDelegate) {}
|
||||
|
||||
public var rx_contentOffset: ControlProperty<CGPoint> {}
|
||||
public var contentOffset: ControlProperty<CGPoint> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UIBarButtonItem {
|
||||
extension Reactive where Base: UIBarButtonItem {
|
||||
|
||||
public var rx_tap: ControlEvent<Void> {}
|
||||
public var tap: ControlEvent<Void> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UISlider {
|
||||
extension Reactive where Base: UISlider {
|
||||
|
||||
public var rx_value: ControlProperty<Float> {}
|
||||
public var value: ControlProperty<Float> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UITableView {
|
||||
extension Reactive where Base: UITableView {
|
||||
|
||||
public var rx_dataSource: DelegateProxy {}
|
||||
public var dataSource: DelegateProxy {}
|
||||
|
||||
public func rx_setDataSource(dataSource: UITableViewDataSource) -> Disposable {}
|
||||
public func setDataSource(dataSource: UITableViewDataSource) -> Disposable {}
|
||||
|
||||
public func rx_itemsWithCellFactory(source: O)(cellFactory: (UITableView, Int, S.Iterator.Element) -> UITableViewCell) -> Disposable {}
|
||||
public func itemsWithCellFactory(source: O)(cellFactory: (UITableView, Int, S.Iterator.Element) -> UITableViewCell) -> Disposable {}
|
||||
|
||||
public func rx_itemsWithCellIdentifier(cellIdentifier: String, cellType: Cell.Type = Cell.self)(source: O)(configureCell: (Int, S.Iterator.Element, Cell) -> Void) -> Disposable {}
|
||||
public func itemsWithCellIdentifier(cellIdentifier: String, cellType: Cell.Type = Cell.self)(source: O)(configureCell: (Int, S.Iterator.Element, Cell) -> Void) -> Disposable {}
|
||||
|
||||
public func rx_itemsWithDataSource(dataSource: DataSource)(source: O) -> Disposable {}
|
||||
public func itemsWithDataSource(dataSource: DataSource)(source: O) -> Disposable {}
|
||||
|
||||
public var rx_itemSelected: ControlEvent<IndexPath> {}
|
||||
public var itemSelected: ControlEvent<IndexPath> {}
|
||||
|
||||
public var rx_itemDeselected: ControlEvent<IndexPath> {}
|
||||
public var itemDeselected: ControlEvent<IndexPath> {}
|
||||
|
||||
public var rx_itemInserted: ControlEvent<IndexPath> {}
|
||||
public var itemInserted: ControlEvent<IndexPath> {}
|
||||
|
||||
public var rx_itemDeleted: ControlEvent<IndexPath> {}
|
||||
public var itemDeleted: ControlEvent<IndexPath> {}
|
||||
|
||||
public var rx_itemMoved: ControlEvent<ItemMovedEvent> {}
|
||||
public var itemMoved: ControlEvent<ItemMovedEvent> {}
|
||||
|
||||
// This method only works in case one of the `rx_itemsWith*` methods was used, or data source implements `SectionedViewDataSourceType`
|
||||
public func rx_modelSelected<T>(modelType: T.Type) -> ControlEvent<T> {}
|
||||
// This method only works in case one of the `rx.itemsWith*` methods was used, or data source implements `SectionedViewDataSourceType`
|
||||
public func modelSelected<T>(modelType: T.Type) -> ControlEvent<T> {}
|
||||
|
||||
// This method only works in case one of the `rx_itemsWith*` methods was used, or data source implements `SectionedViewDataSourceType`
|
||||
public func rx_modelDeselected<T>(modelType: T.Type) -> ControlEvent<T> {}
|
||||
// This method only works in case one of the `rx.itemsWith*` methods was used, or data source implements `SectionedViewDataSourceType`
|
||||
public func modelDeselected<T>(modelType: T.Type) -> ControlEvent<T> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UICollectionView {
|
||||
extension Reactive where Base: UICollectionView {
|
||||
|
||||
public var rx_dataSource: DelegateProxy {}
|
||||
public var dataSource: DelegateProxy {}
|
||||
|
||||
public func rx_setDataSource(dataSource: UICollectionViewDataSource) -> Disposable {}
|
||||
public func setDataSource(dataSource: UICollectionViewDataSource) -> Disposable {}
|
||||
|
||||
public func rx_itemsWithCellFactory(source: O)(cellFactory: (UICollectionView, Int, S.Iterator.Element) -> UICollectionViewCell) -> Disposable {}
|
||||
public func itemsWithCellFactory(source: O)(cellFactory: (UICollectionView, Int, S.Iterator.Element) -> UICollectionViewCell) -> Disposable {}
|
||||
|
||||
public func rx_itemsWithCellIdentifier(cellIdentifier: String, cellType: Cell.Type = Cell.self)(source: O)(configureCell: (Int, S.Iterator.Element, Cell) -> Void) -> Disposable {}
|
||||
public func itemsWithCellIdentifier(cellIdentifier: String, cellType: Cell.Type = Cell.self)(source: O)(configureCell: (Int, S.Iterator.Element, Cell) -> Void) -> Disposable {}
|
||||
|
||||
public func rx_itemsWithDataSource(dataSource: DataSource)(source: O) -> Disposable {}
|
||||
public func itemsWithDataSource(dataSource: DataSource)(source: O) -> Disposable {}
|
||||
|
||||
public var rx_itemSelected: ControlEvent<IndexPath> {}
|
||||
public var itemSelected: ControlEvent<IndexPath> {}
|
||||
|
||||
public var rx_itemDeselected: ControlEvent<IndexPath> {}
|
||||
public var itemDeselected: ControlEvent<IndexPath> {}
|
||||
|
||||
// This method only works in case one of the `rx_itemsWith*` methods was used, or data source implements `SectionedViewDataSourceType`
|
||||
public func rx_modelSelected<T>(modelType: T.Type) -> ControlEvent<T> {}
|
||||
// This method only works in case one of the `rx.itemsWith*` methods was used, or data source implements `SectionedViewDataSourceType`
|
||||
public func modelSelected<T>(modelType: T.Type) -> ControlEvent<T> {}
|
||||
|
||||
// This method only works in case one of the `rx_itemsWith*` methods was used, or data source implements `SectionedViewDataSourceType`
|
||||
public func rx_modelSelected<T>(modelType: T.Type) -> ControlEvent<T> {}
|
||||
// This method only works in case one of the `rx.itemsWith*` methods was used, or data source implements `SectionedViewDataSourceType`
|
||||
public func modelSelected<T>(modelType: T.Type) -> ControlEvent<T> {}
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UIGestureRecognizer {
|
||||
extension Reactive where Base: UIGestureRecognizer {
|
||||
|
||||
public var rx_event: ControlEvent<UIGestureRecognizer> {}
|
||||
public var event: ControlEvent<UIGestureRecognizer> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UIImagePickerController {
|
||||
extension Reactive where Base: UIImagePickerController {
|
||||
|
||||
public var rx_didFinishPickingMediaWithInfo: Observable<[String : AnyObject]> {}
|
||||
public var didFinishPickingMediaWithInfo: Observable<[String : AnyObject]> {}
|
||||
|
||||
public var rx_didCancel: Observable<()> {}
|
||||
public var didCancel: Observable<()> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UISegmentedControl {
|
||||
extension Reactive where Base: UISegmentedControl {
|
||||
|
||||
public var rx_value: ControlProperty<Int> {}
|
||||
public var value: ControlProperty<Int> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UISwitch {
|
||||
extension Reactive where Base: UISwitch {
|
||||
|
||||
public var rx_value: ControlProperty<Bool> {}
|
||||
public var value: ControlProperty<Bool> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UIActivityIndicatorView {
|
||||
extension Reactive where Base: UIActivityIndicatorView {
|
||||
|
||||
public var rx_animating: AnyObserver<Bool> {}
|
||||
public var animating: AnyObserver<Bool> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UINavigationItem {
|
||||
extension Reactive where Base: UINavigationItem {
|
||||
|
||||
public var rx_title: AnyObserver<String?> {}
|
||||
public var title: AnyObserver<String?> {}
|
||||
}
|
||||
```
|
||||
|
||||
**OSX**
|
||||
|
||||
```swift
|
||||
extension NSControl {
|
||||
extension Reactive where Base: NSControl {
|
||||
|
||||
public var rx_controlEvent: ControlEvent<()> {}
|
||||
public var controlEvent: ControlEvent<()> {}
|
||||
|
||||
public var rx_enabled: AnyObserver<Bool> {}
|
||||
public var enabled: AnyObserver<Bool> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
|
||||
extension NSSlider {
|
||||
extension Reactive where Base: NSSlider {
|
||||
|
||||
public var rx_value: ControlProperty<Double> {}
|
||||
public var value: ControlProperty<Double> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension NSButton {
|
||||
extension Reactive where Base: NSButton {
|
||||
|
||||
public var rx_tap: ControlEvent<Void> {}
|
||||
public var tap: ControlEvent<Void> {}
|
||||
|
||||
public var rx_state: ControlProperty<Int> {}
|
||||
public var state: ControlProperty<Int> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension NSImageView {
|
||||
extension Reactive where Base: NSImageView {
|
||||
|
||||
public var rx_image: ObserverOf<NSImage?> {}
|
||||
public var image: ObserverOf<NSImage?> {}
|
||||
|
||||
public func rx_imageAnimated(transitionType: String?) -> AnyObserver<NSImage?>
|
||||
public func imageAnimated(transitionType: String?) -> AnyObserver<NSImage?>
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension NSTextField {
|
||||
extension Reactive where Base: NSTextField {
|
||||
|
||||
public var rx_delegate: DelegateProxy {}
|
||||
public var delegate: DelegateProxy {}
|
||||
|
||||
public var rx_text: ControlProperty<String> {}
|
||||
public var text: ControlProperty<String> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UITabBarItem {
|
||||
extension Reactive where Base: UITabBarItem {
|
||||
|
||||
public var rx_badgeValue: AnyObserver<String?> {}
|
||||
public var badgeValue: AnyObserver<String?> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```swift
|
||||
extension UITabBar {
|
||||
extension Reactive where Base: UITabBar {
|
||||
|
||||
public var rx_didSelectItem: ControlEvent<UITabBarItem> {}
|
||||
public var didSelectItem: ControlEvent<UITabBarItem> {}
|
||||
|
||||
public var rx_willBeginCustomizing: ControlEvent<[UITabBarItem]> {}
|
||||
public var willBeginCustomizing: ControlEvent<[UITabBarItem]> {}
|
||||
|
||||
public var rx_didBeginCustomizing: ControlEvent<[UITabBarItem]> {}
|
||||
public var didBeginCustomizing: ControlEvent<[UITabBarItem]> {}
|
||||
|
||||
public var rx_willEndCustomizing: ControlEvent<(items: [UITabBarItem], changed: Bool)> {}
|
||||
public var willEndCustomizing: ControlEvent<(items: [UITabBarItem], changed: Bool)> {}
|
||||
|
||||
public var rx_didEndCustomizing: ControlEvent<(items: [UITabBarItem], changed: Bool)> {}
|
||||
public var didEndCustomizing: ControlEvent<(items: [UITabBarItem], changed: Bool)> {}
|
||||
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -72,17 +72,17 @@ b.value = -8 // doesn't print anything
|
|||
|
||||
## Simple UI bindings
|
||||
|
||||
* Instead of binding to variables, let's bind to `UITextField` values using the `rx_text` property
|
||||
* Instead of binding to variables, let's bind to `UITextField` values using the `rx.text` property
|
||||
* Next, `map` the `String` into an `Int` and determine if the number is prime using an async API
|
||||
* If the text is changed before the async call completes, a new async call will replace it via `concat`
|
||||
* Bind the results to a `UILabel`
|
||||
|
||||
```swift
|
||||
let subscription/*: Disposable */ = primeTextField.rx_text // type is Observable<String>
|
||||
let subscription/*: Disposable */ = primeTextField.rx.text // type is Observable<String>
|
||||
.map { WolframAlphaIsPrime(Int($0) ?? 0) } // type is Observable<Observable<Prime>>
|
||||
.concat() // type is Observable<Prime>
|
||||
.map { "number \($0.n) is prime? \($0.isPrime)" } // type is Observable<String>
|
||||
.bindTo(resultLabel.rx_text) // return Disposable that can be used to unbind everything
|
||||
.bindTo(resultLabel.rx.text) // return Disposable that can be used to unbind everything
|
||||
|
||||
// This will set `resultLabel.text` to "number 43 is prime? true" after
|
||||
// server call completes.
|
||||
|
|
@ -108,7 +108,7 @@ Let's give it a shot.
|
|||
```swift
|
||||
// bind UI control values directly
|
||||
// use username from `usernameOutlet` as username values source
|
||||
self.usernameOutlet.rx_text
|
||||
self.usernameOutlet.rx.text
|
||||
.map { username in
|
||||
|
||||
// synchronous validation, nothing special here
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ Additional way to automatically dispose subscription on dealloc is to use `takeU
|
|||
|
||||
```swift
|
||||
sequence
|
||||
.takeUntil(self.deallocated)
|
||||
.takeUntil(self.rx.deallocated)
|
||||
.subscribe {
|
||||
print($0)
|
||||
}
|
||||
|
|
@ -554,8 +554,8 @@ Behavior for URL observables is equivalent.
|
|||
This is how HTTP requests are wrapped in Rx. It's pretty much the same pattern like the `interval` operator.
|
||||
|
||||
```swift
|
||||
extension NSURLSession {
|
||||
public func rx_response(request: NSURLRequest) -> Observable<(NSData, NSURLResponse)> {
|
||||
extension Reactive where Base: NSURLSession {
|
||||
public func response(request: NSURLRequest) -> Observable<(NSData, NSURLResponse)> {
|
||||
return Observable.create { observer in
|
||||
let task = self.dataTaskWithRequest(request) { (data, response, error) in
|
||||
guard let response = response, data = data else {
|
||||
|
|
@ -933,14 +933,14 @@ There are two built in ways this library supports KVO.
|
|||
|
||||
```swift
|
||||
// KVO
|
||||
extension NSObject {
|
||||
public func rx_observe<E>(type: E.Type, _ keyPath: String, options: NSKeyValueObservingOptions, retainSelf: Bool = true) -> Observable<E?> {}
|
||||
extension Reactive where Base: NSObject {
|
||||
public func observe<E>(type: E.Type, _ keyPath: String, options: NSKeyValueObservingOptions, retainSelf: Bool = true) -> Observable<E?> {}
|
||||
}
|
||||
|
||||
#if !DISABLE_SWIZZLING
|
||||
// KVO
|
||||
extension NSObject {
|
||||
public func rx_observeWeakly<E>(type: E.Type, _ keyPath: String, options: NSKeyValueObservingOptions) -> Observable<E?> {}
|
||||
extension Reactive where Base: NSObject {
|
||||
public func observeWeakly<E>(type: E.Type, _ keyPath: String, options: NSKeyValueObservingOptions) -> Observable<E?> {}
|
||||
}
|
||||
#endif
|
||||
```
|
||||
|
|
@ -951,7 +951,7 @@ Example how to observe frame of `UIView`.
|
|||
|
||||
```swift
|
||||
view
|
||||
.rx_observe(CGRect.self, "frame")
|
||||
.rx.observe(CGRect.self, "frame")
|
||||
.subscribe(onNext: { frame in
|
||||
...
|
||||
})
|
||||
|
|
@ -961,15 +961,15 @@ or
|
|||
|
||||
```swift
|
||||
view
|
||||
.rx_observeWeakly(CGRect.self, "frame")
|
||||
.rx.observeWeakly(CGRect.self, "frame")
|
||||
.subscribe(onNext: { frame in
|
||||
...
|
||||
})
|
||||
```
|
||||
|
||||
### `rx_observe`
|
||||
### `rx.observe`
|
||||
|
||||
`rx_observe` is more performant because it's just a simple wrapper around KVO mechanism, but it has more limited usage scenarios
|
||||
`rx.observe` is more performant because it's just a simple wrapper around KVO mechanism, but it has more limited usage scenarios
|
||||
|
||||
* it can be used to observe paths starting from `self` or from ancestors in ownership graph (`retainSelf = false`)
|
||||
* it can be used to observe paths starting from descendants in ownership graph (`retainSelf = true`)
|
||||
|
|
@ -978,14 +978,14 @@ view
|
|||
E.g.
|
||||
|
||||
```swift
|
||||
self.rx_observe(CGRect.self, "view.frame", retainSelf: false)
|
||||
self.rx.observe(CGRect.self, "view.frame", retainSelf: false)
|
||||
```
|
||||
|
||||
### `rx_observeWeakly`
|
||||
### `rx.observeWeakly`
|
||||
|
||||
`rx_observeWeakly` has somewhat slower than `rx_observe` because it has to handle object deallocation in case of weak references.
|
||||
`rx.observeWeakly` has somewhat slower than `rx.observe` because it has to handle object deallocation in case of weak references.
|
||||
|
||||
It can be used in all cases where `rx_observe` can be used and additionally
|
||||
It can be used in all cases where `rx.observe` can be used and additionally
|
||||
|
||||
* because it won't retain observed target, it can be used to observe arbitrary object graph whose ownership relation is unknown
|
||||
* it can be used to observe `weak` properties
|
||||
|
|
@ -993,7 +993,7 @@ It can be used in all cases where `rx_observe` can be used and additionally
|
|||
E.g.
|
||||
|
||||
```swift
|
||||
someSuspiciousViewController.rx_observeWeakly(Bool.self, "behavingOk")
|
||||
someSuspiciousViewController.rx.observeWeakly(Bool.self, "behavingOk")
|
||||
```
|
||||
|
||||
### Observing structs
|
||||
|
|
@ -1004,7 +1004,7 @@ KVO is an Objective-C mechanism so it relies heavily on `NSValue`.
|
|||
|
||||
When observing some other structures it is necessary to extract those structures from `NSValue` manually.
|
||||
|
||||
[Here](../RxCocoa/Common/KVORepresentable+CoreGraphics.swift) are examples how to extend KVO observing mechanism and `rx_observe*` methods for other structs by implementing `KVORepresentable` protocol.
|
||||
[Here](../RxCocoa/Common/KVORepresentable+CoreGraphics.swift) are examples how to extend KVO observing mechanism and `rx.observe*` methods for other structs by implementing `KVORepresentable` protocol.
|
||||
|
||||
## UI layer tips
|
||||
|
||||
|
|
@ -1070,7 +1070,7 @@ let request = NSURLRequest(URL: NSURL(string: "http://en.wikipedia.org/w/api.php
|
|||
If you want to just execute that request outside of composition with other observables, this is what needs to be done.
|
||||
|
||||
```swift
|
||||
let responseJSON = NSURLSession.sharedSession().rx_JSON(request)
|
||||
let responseJSON = NSURLSession.sharedSession().rx.JSON(request)
|
||||
|
||||
// no requests will be performed up to this point
|
||||
// `responseJSON` is just a description how to fetch the response
|
||||
|
|
@ -1093,7 +1093,7 @@ cancelRequest.dispose()
|
|||
In case you want a more low level access to response, you can use:
|
||||
|
||||
```swift
|
||||
NSURLSession.sharedSession().rx_response(myNSURLRequest)
|
||||
NSURLSession.sharedSession().rx.response(myNSURLRequest)
|
||||
.debug("my request") // this will print out information to console
|
||||
.flatMap { (data: NSData!, response: NSURLResponse!) -> Observable<String> in
|
||||
if let response = response as? NSHTTPURLResponse {
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ E.g.
|
|||
This is a typical beginner example.
|
||||
|
||||
```swift
|
||||
let results = query.rx_text
|
||||
let results = query.rx.text
|
||||
.throttle(0.3, scheduler: MainScheduler.instance)
|
||||
.flatMapLatest { query in
|
||||
fetchAutoCompleteItems(query)
|
||||
|
|
@ -172,11 +172,11 @@ let results = query.rx_text
|
|||
|
||||
results
|
||||
.map { "\($0.count)" }
|
||||
.bindTo(resultCount.rx_text)
|
||||
.bindTo(resultCount.rx.text)
|
||||
.addDisposableTo(disposeBag)
|
||||
|
||||
results
|
||||
.bindTo(resultsTableView.rx_itemsWithCellIdentifier("Cell")) { (_, result, cell) in
|
||||
.bindTo(resultsTableView.rx.itemsWithCellIdentifier("Cell")) { (_, result, cell) in
|
||||
cell.textLabel?.text = "\(result)"
|
||||
}
|
||||
.addDisposableTo(disposeBag)
|
||||
|
|
@ -195,7 +195,7 @@ So, what are the problems with this code?:
|
|||
A more appropriate version of the code would look like this:
|
||||
|
||||
```swift
|
||||
let results = query.rx_text
|
||||
let results = query.rx.text
|
||||
.throttle(0.3, scheduler: MainScheduler.instance)
|
||||
.flatMapLatest { query in
|
||||
fetchAutoCompleteItems(query)
|
||||
|
|
@ -207,11 +207,11 @@ let results = query.rx_text
|
|||
|
||||
results
|
||||
.map { "\($0.count)" }
|
||||
.bindTo(resultCount.rx_text)
|
||||
.bindTo(resultCount.rx.text)
|
||||
.addDisposableTo(disposeBag)
|
||||
|
||||
results
|
||||
.bindTo(resultTableView.rx_itemsWithCellIdentifier("Cell")) { (_, result, cell) in
|
||||
.bindTo(resultTableView.rx.itemsWithCellIdentifier("Cell")) { (_, result, cell) in
|
||||
cell.textLabel?.text = "\(result)"
|
||||
}
|
||||
.addDisposableTo(disposeBag)
|
||||
|
|
@ -222,7 +222,7 @@ Making sure all of these requirements are properly handled in large systems can
|
|||
The following code looks almost the same:
|
||||
|
||||
```swift
|
||||
let results = query.rx_text.asDriver() // This converts a normal sequence into a `Driver` sequence.
|
||||
let results = query.rx.text.asDriver() // This converts a normal sequence into a `Driver` sequence.
|
||||
.throttle(0.3, scheduler: MainScheduler.instance)
|
||||
.flatMapLatest { query in
|
||||
fetchAutoCompleteItems(query)
|
||||
|
|
@ -231,11 +231,11 @@ let results = query.rx_text.asDriver() // This converts a normal sequence
|
|||
|
||||
results
|
||||
.map { "\($0.count)" }
|
||||
.drive(resultCount.rx_text) // If there is a `drive` method available instead of `bindTo`,
|
||||
.drive(resultCount.rx.text) // If there is a `drive` method available instead of `bindTo`,
|
||||
.addDisposableTo(disposeBag) // that means that the compiler has proven that all properties
|
||||
// are satisfied.
|
||||
results
|
||||
.drive(resultTableView.rx_itemsWithCellIdentifier("Cell")) { (_, result, cell) in
|
||||
.drive(resultTableView.rx.itemsWithCellIdentifier("Cell")) { (_, result, cell) in
|
||||
cell.textLabel?.text = "\(result)"
|
||||
}
|
||||
.addDisposableTo(disposeBag)
|
||||
|
|
@ -246,7 +246,7 @@ So what is happening here?
|
|||
This first `asDriver` method converts the `ControlProperty` unit to a `Driver` unit.
|
||||
|
||||
```swift
|
||||
query.rx_text.asDriver()
|
||||
query.rx.text.asDriver()
|
||||
```
|
||||
|
||||
Notice that there wasn't anything special that needed to be done. `Driver` has all of the properties of the `ControlProperty` unit, plus some more. The underlying observable sequence is just wrapped as a `Driver` unit, and that's it.
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ KVO observing, async operations and streams are all unified under [abstraction o
|
|||
</tr>
|
||||
<tr>
|
||||
<td><div class="highlight highlight-source-swift"><pre>
|
||||
let searchResults = searchBar.rx_text
|
||||
let searchResults = searchBar.rx.text
|
||||
.throttle(0.3, scheduler: MainScheduler.instance)
|
||||
.distinctUntilChanged()
|
||||
.flatMapLatest { query -> Observable<[Repository]> in
|
||||
|
|
@ -96,7 +96,7 @@ let searchResults = searchBar.rx_text
|
|||
<tr>
|
||||
<td width="30%"><div class="highlight highlight-source-swift"><pre>
|
||||
searchResults
|
||||
.bindTo(tableView.rx_itemsWithCellIdentifier("Cell")) {
|
||||
.bindTo(tableView.rx.itemsWithCellIdentifier("Cell")) {
|
||||
(index, repository: Repository, cell) in
|
||||
cell.textLabel?.text = repository.name
|
||||
cell.detailTextLabel?.text = repository.url
|
||||
|
|
|
|||
Loading…
Reference in New Issue