Binding 1.1.0

Binding 1.1.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Unclaimed.


Downloads

Total2,623
Week0
Month0

Installs

Apps11
Test Targets2
powered by Segment

GitHub

Stars12
Watchers2
Forks1
Issues1
Contributors1
Pull Requests1

Code

Files2
LOCLines of Code 105


Binding 1.1.0

  • By
  • Jeremy Tregunna

There are many options for bindings in iOS, not the least of which being ReactiveCocoa. While RAC is great, and you should seriously consider using it for your applications, sometimes you need just a simple binding, and words like flatMap, command and signal can be intimidating for your teammates. This is why I built Binding.

The goal of Binding is to fill that spot—The "less scary"—observables spot.

Example

Let's assume that in your view controller, you have a tableview, and you follow good design practices in separating your data source into a separate object. It manages loading of your resources, and changes a publicly visible property. This is your indication on when to reload the tableview! We can do that easily:

self.resultsBinding = [Bind(self.dataStore, results) next:^(id value) {
    [self.tableView reloadData];
}];

But what if you are loading a comment view, and you also want to update the title with the count of items that come in? Well, the new value is passed to your next block. Consider extending the above like so:

self.resultsBinding = [Bind(self.dataStore, results) next:^(NSArray* results) {
    self.title = [NSString stringWithFormat:@"Comments (%tu)", [results count]];

    [self.tableView reloadData];
}];

We don't have to stop there however, if you want to debug what's coming back from that, you could modify the block directly, or add another next block like so:

[self.resultsBinding next:^(NSArray* results) {
    NSLog(@"results = %@", results);
}];

Both blocks will be called when the results change.

License

The terms under which use and distribution of this library is governed may be found in the LICENSE file.