O'Reilly logo

Learning Swift, 2nd Edition by Jon Manning, Tim Nugent, Paris Buttfield-Addison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. Working with Files and File Types

At the moment, the iOS app can work with the text content of note documents, but doesn’t really know anything about attachments that might have been added through the macOS app.

In this chapter, we’ll add support for working with attachments to the iOS app, as well as make its handling of note documents more robust. We’ll do this by adding—you guessed it—more user interface to:

  • Display any attachments

  • Handle conflict resolution, for when a file is synced from multiple devices

  • Add Quick Look support, to display a thumbnail preview of attachments

Setting Up the Interface for Attachments

First, we’ll update the interface for the document view controller to support showing the list of attachments. This will involve reworking everything, as well as some reasonably complex constraints, so it’s easier to start from scratch:

  1. Open Main.storyboard.

  2. Delete the text view from the document view controller’s interface. We’ll be reconstructing the interface, with room for the attachments to be displayed, so it’s easier to remove everything than it is to rearrange.

  3. It’ll be easier to do this without the top bar in the way, so select the document view controller, and in the Simulated Metrics section of the Inspector, change Top Bar from Inferred to None (Figure 10-1).

    lsw2 1001
    Figure 10-1. Setting the mode of the top bar
  4. Drag a UIScrollView ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required