RxSugar 0.1.1

RxSugar 0.1.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Nov 2016
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by James Rantanen, Mark Sands.



RxSugar 0.1.1

  • By
  • James Rantanen, Mark Sands and Asynchrony

RxSugar Logo RxSugar

Simple RxSwift extensions for interacting with Apple APIs.

Operators that improve visualization of data flow

observer <~ observable

The <~ subscribes an observer to an observable. Observer can be any ObserverType, Variable, or (value)->()closure. Observable can be any ObservableType, Variable, or ObservableConvertibleType. This operator returns a Disposable.

disposableCollection ++ disposable

The ++ appends a Disposable to a collection of disposables (DisposeBag or CompositeDisposable) and returns the collection.

These operators used in combination result in an easy to visualize data flow:

static func bindView(view: View, model: Model, selectionHandler:(SearchResult)->()) {
    view.rxs.disposeBag
        ++ view.searchResults <~ model.searchResults
        ++ model.searchTerm <~ view.searchTerm
        ++ selectionHandler <~ view.selectionEvents
}

Foundation / UIKit extensions

RxSugar adds Sugar to all NSObjects as a property called rxs. The rxs property contains RxSwift bindings for many common APIs. Here are a few examples:

NSObject

object.rxs.disposeBag - a collection of dispoasables that will be disposed on deinit

UIButton

button.rxs.tap - an Observable<Void> that sends an event on every .TouchUpInside control event.

UITextField

textField.rxs.text - a ValueBinding<String> that sends an event on every .EditingChanged control event and sets the control’s text for every event sent to it.

textField.rxs.attributedText - a ValueBinding<NSAttributedString> that sends an event on every .EditingChanged control event and sets the control’s attributedText for every event sent to it.

UITextView

Same as UITextField, but using the UITextViewTextDidChangeNotification to drive events

Adding your own Sugar

TargetActionObservable and ValueBinding provide the building blocks for creating your own interface “sugar” similar to the examples above.