Simple Swift Variable<Value>
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Bindable.xcodeproj
BindableTests
Example
Sources
.gitignore
Bindable.podspec
LICENSE
README.md

README.md

Bindable


This is the first development version of the Bindable UI databinding library. API is not yet stable, use at your own risk.

Installation

Include the following line in your Podfile:

pod 'Bindable/NSObject', :git => 'git@github.com:Q42/Bindable.git'

Or, via HTTPS:

pod 'Bindable/NSObject', :git => 'https://github.com/Q42/Bindable.git'

Example

Create a view model:

class MainViewModel {
  private let ageSource = VariableSource<Int>(value: 0)

  let age: Variable<Int>
  let title: Variable<String>
  
  init() {
    age = ageSource.variable
    title = age.map { "Age: \($0)" }
  }


  func up() {
    ageSource.value += 1
  }

  func down() {
    ageSource.value -= 1
  }
}

And use it in your view controller:

let viewModel = MainViewModel()

// Manually subscribe for change events
viewModel.age.subscribe { event in
  print("New age: \(event.value)")
}

// Or data bind a UILabel
titleLabel.bind(\.text, to: viewModel.title)

CocoaHeadsNL presentation

Tom Lokhorst presented at the September 2017 CocoaHeadsNL meetup. Comparing several methods for reactivally updating UI's, including Bindable. The description of Bindable starts at 27:33:

https://vimeo.com/237530468#t=27m33s

Releases

  • 0.5.0 - 2018-09-13 - Update to Swift 4.2, refactor internal to use classes
  • 0.4.1 - 2018-05-02 - Add Variable+KVO
  • 0.3.0 - 2018-04-24 - Split out NSObject subspec
  • 0.2.0 - 2018-02-26 - Fix occasional "execute on wrong queue" issue
  • 0.1.0 - 2017-05-31 - Initial public release
  • 0.0.0 - 2016-12-14 - Initial private version for project at Q42

License & Credits

Bindable is written by Tom Lokhorst of Q42 and available under the MIT license, so feel free to use it in commercial and non-commercial projects.