---
title: "#282: Taming the Keyboard with Typist ⌨️"
url: https://littlebitesofcocoa.com/282-taming-the-keyboard-with-typist
author: Jake Marsh
published: 2016-10-31
topics: ["Libraries","UIKit"]
description: "Properly responding integrating with the software keyboard is a big part of building a solid iOS app. Traditionally, this would involve observing..."
---

# #282: Taming the Keyboard with Typist ⌨️

By Jake Marsh, October 31, 2016. HTML: https://littlebitesofcocoa.com/282-taming-the-keyboard-with-typist

Properly responding integrating with the software _keyboard_ is a big part of building a solid **iOS app**. Traditionally, this would involve observing `NSNotificationCenter` **notifications** and some pretty lengthy boilerplate code. Today we'll look at a great little library from [Toto Tvalavadze](https://github.com/totocaster) called [Typist](https://github.com/totocaster/Typist) that can improve all this. Let's check it out.

[Typist](https://github.com/totocaster/Typist) works by exposing a way for us to easily <i>"opt-in"</i> to certain _keyboard_ **events**:

``` swift
Typist.shared
  .on(event: .didShow) { (options) in
    // TODO
  }
  .start()
}
```

Yep. That's it. Gone are the wildly verbose notifications and complicated setup.

<i>(**Note:** We're not required to use [Typist's](https://github.com/totocaster/Typist) [singleton instance](https://littlebitesofcocoa.com/4), but it's provided for convenience).</i>

[Typist](https://github.com/totocaster/Typist) provides this same interface for a bunch of useful **events**:

``` swift
Typist.shared
  .on(event: .willShow) { _ in /* TODO */ }
  .on(event: .didShow) { _ in /* TODO */ }
  .on(event: .willHide) { _ in /* TODO */ }
  .on(event: .didHide) { _ in /* TODO */ }
  .on(event: .willChangeFrame) { _ in /* TODO */ }
  .on(event: .didChangeFrame) { _ in /* TODO */ }
  .start()
}
```

Finally, inside each **event** closure, we're given a `Typist.KeyboardOptions` type that contains **strongly-typed properties** describing the **event**:

``` swift
Typist.shared
  .on(event: .willShow) { (options) in
    guard options.belongsToCurrentApp else { return }

    updateLayout(for: options.endFrame)
  }
  .on(event: .willHide) { (options) in
    guard options.belongsToCurrentApp else { return }

    updateLayout(for: options.endFrame)
  }
  .start()
}
```

Here we're `guard`-ing to make sure the _keyboard_ belongs to our **app**, and returning early if not.

Then, we use the `endFrame` property to adjust our own **views** to accomodate the _keyboard_.

Neat!

[Typist](https://github.com/totocaster/Typist)'s **options** type also provides `startFrame`, `animationCurve`, and `animationDuration` **properties** to help us match our **app's** animation to the _keyboard's_.

Learn more about [Typist](https://github.com/totocaster/Typist) at [http://git.io/typist](http://git.io/typist)

<p></p>
