24

Here’s an open source library called Bond from Srdan Rasic that adds a new operator to Swift that makes binding dead simple.

This example from the readme shows to bind the state of a text field to a label with Bond you could simply use:

textField ~> label

And this more complex example shows how one could dynamically update a table view with a repository data source object:

repositories.map { [unowned self] (repository: Repository) -> RepositoryTableViewCell in
      let cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as RepositoryTableViewCell
      repository.name ~> cell.nameLabel
      repository.photo ~> cell.avatarImageView
      return cell
    } ~> self.tableView

Included within Bond are many helpers specifically for working with UIKit, arrays, KVO, and more with a number of code snippets in the readme, and a nice example showing how to dynamically update a table view with updated data.

You can find Bond on Github here.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>