What is GlueKit?

GlueKit is a Swift framework for creating observables and manipulating them in interesting and useful ways. It is called GlueKit because it lets you stick stuff together.

GlueKit contains type-safe analogues for Cocoa’s Key-Value Coding and Key-Value Observing subsystems, written in pure Swift. Besides providing the basic observation mechanism, GlueKit also supports full-blown key path observing, where a sequence of properties starting at a particular entity is observed at once. (E.g., you can observe a person’s best friend’s favorite color, which might change whenever the person gets a new best friend, or when the friend changes their mind about which color they like best.)

(Note though that GlueKit’s keys are functions so they aren’t as easy to serialize as KVC’s string-based keys and key paths. It is definitely possible to implement serializable type-safe keys in Swift; but it involves some boilerplate code that’s better handled by code generation or core language enhancements such as property behaviors or improved reflection capabilities.)

Like KVC/KVO, GlueKit supports observing not only individual values, but also collections like sets or arrays. This includes full support for key path observing, too — e.g., you can observe a person’s children’s children as a single set. These observable collections report fine-grained incremental changes (e.g., “‘foo’ was inserted at index 5”), allowing you to efficiently react to their changes.

Beyond key path observing, GlueKit also provides a rich set of transformations and combinations for observables as a more flexible and extensible Swift version of KVC’s collection operators. E.g., given an observable array of integers, you can (efficiently!) observe the sum of its elements; you can filter it for elements that match a particular predicate; you can get an observable concatenation of it with another observable array; and you can do much more.

You can use GlueKit’s observable arrays to efficiently provide data to a UITableView or UICollectionView, including providing them with incremental changes for animated updates. This functionality is roughly equivalent to what NSFetchedResultsController does in Core Data.

GlueKit is written in pure Swift; it does not require the Objective-C runtime for its functionality. However, it does provide easy-to-use adapters that turn KVO-compatible key paths on NSObjects into GlueKit observables.

GlueKit hasn’t been officially released yet. Its API is still in flux, and it has wildly outdated and woefully incomplete documentation. However, the project is getting close to a feature set that would make a coherent 1.0 version; I expect to have a useful first release before the end of 2016.

Overview

  • Pricing: Free
  • Resource Link: https://github.com/attaswift/GlueKit
  • Resource Maker: attaswift
  • Mobile Platform Destination: iOS Apps
  • Mobile Platform Support: Native iOS
  • Programming Languages: Swift
  • CocoaPods: GlueKit
  • Carthage: attaswift/GlueKit
  • Swift Package Manager: https://github.com/attaswift/GlueKit.git