Chapter 15. Polishing the iOS App

Our iOS notes application is now largely feature-complete. It’s fully operational, but could do with a few more finishing touches to add some polish. In this chapter, we’ll add a text-to-speech option to the menu that appears when text is selected, support for opening links in the provided web browser view controller, overall app settings, as well as undo support and image filters.

Speaking Text

Apple’s platforms have traditionally had great support for text-to-speech. In our app, we want to add the ability to select text and speak it by tapping on a Speak button that appears in the editing menu next to the Cut, Copy, and Paste buttons. We’ll do this using the UIMenuController class.

To include speech synthesis, we use the AVSpeechSynthesizer object, which is part of the AVFoundation framework. AVSpeechSynthesizer provides the ability to produce synthesized speech from any text, with a controller for speed and pitch, as well as a selection of voices (depending on iOS version).

  1. First, we’ll add the actual speech synthesis object. Add the speechSynthesizer property to DocumentViewController:

      let speechSynthesizer = AVSpeechSynthesizer()
  2. Next, we need to add the method to the menu controller. Menu controllers are provided by UIMenuController and are responsible for displaying the editing menu that can be made to appear on a selected object or piece of text in iOS. The editing menu displays the Cut, Copy, and Paste commands, among other things ...

Get Learning Swift now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.