Today we'll check out a library called Tactile. It's a "Swiftier" way to respond to gesture recognizers and control events. Let's get started.

Tactile gives us a safer, more idiomatic way to install/react to gesture recognizers (Check Bite #38 for gesture basics).

In it's simplest form, Tactile works like this:

let tapGR = UITapGestureRecognizer()
tapGR.numberOfTapsRequired = 2

view.on(tapGR) { (tapGR: UITapGestureRecognizer) in
  // ...
}

We can also react to specific state changes:

let panGR = UIPanGestureRecognizer()
view.on(panGR, [.Began, .Ended], beganOrEnded)

func beganOrEnded(panGR: UIPanGestureRecognizer) {
  // ...
}

Tactile also adds similar functions to UIControl:

button.on(.TouchUpInside, tapped)
button.on([
  .TouchUpInside: tapped,
  .TouchUpOutside: cancelledTap
])

We can attach a single recognizer to multiple views:

viewA.on(tapGR, { tapGR in /* ... */ })
viewB.on(tapGR, { tapGR in /* ... */ })

Last but not least, we can remove all recognizers with

view.off()

just one with:

view.off(tap)

or all of a type with:

view.off(UITapGestureRecognizer.self)

More info about Tactile can be found at git.io/tactile