Chapter 9. Document-Based Apps

An application can allow the user to browse and edit iCloud-backed documents using various objects and view controllers that are provided in the iOS SDK, such as UIDocumentBrowserViewController. In the iOS SDK, you can find every class and technology that your app might require in order to create professional document-based applications for all kinds of documents.

iOS takes care of presenting and exporting a document’s data to your application from iCloud. Another complex operation that iOS can take care of is syncing multiple simultaneous edit operations on the same file. What your application is responsible for is presenting the data to the user, allowing the user to edit that data (if possible), and then saving the data back to iOS, which in turn is responsible for saving that data back to iCloud.

9.1 Supporting File Browsing in Your App

Problem

You want to create a document-based application and would like to start by allowing the user to browse their existing documents.

Solution

Follow these steps:

  1. Ensure your application’s root view controller is of type UIDocumentBrowserViewController.
  2. Make sure that this root view controller is not embedded inside a navigation controller. The document browser has its own navigation controller and should not be wrapped inside an extra navigation controller.
  3. In your app delegate, read your window property’s rootViewController, now of type UIDocumentBrowserViewController, and set its delegate property to ...

Get iOS 11 Swift Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.