---
title: "#301: The Dictionary Hiding Inside UIKit 📖📼"
url: https://littlebitesofcocoa.com/301-the-dictionary-hiding-inside-uikit
author: Jake Marsh
date: 2017-03-06
published: 2017-03-06
topics: ["B-sides","UIKit"]
description: "Today we'll continue our series on finding hidden gems in UIKit with UIReferenceLibraryViewController. Believe it or not there's a entire dictionary (yes..."
---

# #301: The Dictionary Hiding Inside UIKit 📖📼

By Jake Marsh, March 6, 2017. HTML: https://littlebitesofcocoa.com/301-the-dictionary-hiding-inside-uikit

Today we'll continue our [series](https://www.littlebitesofcocoa.com/topics/80-b-sides?v=l) on finding hidden gems in _UIKit_ with _UIReferenceLibraryViewController_.

Believe it or not there's a <i>entire dictionary</i> (yes like for viewing the definition of words/terms) just hanging out inside _UIKit_.

Let's give it a try! 📖

We can present a new _reference library view controller_ for any word/term we want like this:

``` swift
present(
  UIReferenceLibraryViewController(term: "Spaceship"),
  animated: true, 
  completion: nil
)
```

<img src="https://media.littlebitesofcocoa.com/301-1.png" style="max-width: 375px; border-radius: 4px;" />

Very cool.

This works great, but things start to break down when we look for something and it's nowhere to be found:

<img src="https://media.littlebitesofcocoa.com/301-2.png" style="max-width: 375px; border-radius: 4px;" />

We can fix this by checking if a term can be found before presenting, using the **static** `dictionaryHasDefinition(forTerm:)` function:

``` swift
if UIReferenceLibraryViewController.dictionaryHasDefinition(forTerm: term) {
  present(
    UIReferenceLibraryViewController(term: term),
    animated: true, 
    completion: nil
  )
}
```

Much better.

_UIReferenceLibraryViewController_ supports many different languages. New languages can be installed using the <i>"Manage"</i> option in the bottom-left:

<img src="https://media.littlebitesofcocoa.com/301-5.png" style="max-width: 375px; border-radius: 4px;" />

Finally, it's worth noting that we get definition functionality for "free" in `UITextFields` via the "Look Up" item in the `UIMenu` that's shown when a user selects some text:

<img src="https://media.littlebitesofcocoa.com/301-3.png" style="max-width: 375px; border-radius: 4px;" />

... and it's <i>**also**</i> worth noting that the **view controller** that appears when a user taps one of these <i>"Look Up"</i> **menu items** in a `UITextField` appears to be <i>**far more advanced**</i> than the what we get when presenting a plain ol' _UIReferenceLibraryViewController_:

<img src="https://media.littlebitesofcocoa.com/301-4.png" style="max-width: 375px; border-radius: 4px;" />

The **Dictionary** results are still present, but we also get results across <i>Music</i>, <i>Wikipedia</i>, <i>Movies</i>, <i>Websites</i>, and even the <i>App Store</i>. Very cool.

(And nope, **UIKit** does not seem to provide a way to trigger this fancier view controller directly. Anyone interested in this should probably [file a Radar](https://littlebitesofcocoa.com/201-how-to-file-a-bug-with-apple).)

That's all for today. Those who want more _UIKit B-Sides_ can check out [these bites here](https://www.littlebitesofcocoa.com/topics/80-b-sides?v=l).

<p></p>
