Skip to main content
main-content
Top

About this book

Rise above the basics of Xcode app development to implement tools like Share buttons and activity view controllers to share document content including parts of documents with other users and with other devices. This book fills the gap so that developers with even a fundamental knowledge of iOS and Swift can implement document creation, saving, and sharing in their apps.

Since the launch of iPhone in 2007, users and developers have struggled with the fact that the file system is hidden. Fortunately the Files app in iOS 11 now offers this feature and it is supported by Apple apps such as Numbers, Pages, and Keynote as well as by the few third-party apps that support documents.

By using the standard formats described in this book, you can make your app’s data shareable to and from other apps like Numbers, Pages, and Word. Files also provides an interface to tools such as Dropbox and iCloud so that users can open and modify documents in them. If you combine standard formats such as .doc, .docx, .jpeg, and .jpg with Dropbox and eMail, you have a simple way to implement and use cross-platform sharing to Macs, PCs, and Android devices.

Implementing iOS and macOS Documents with the Files App provides the combination of skills developers need to build these types of apps—working with files and constructing documents.

What You'll Learn

Add Document Support to Your Apps

Share your documents with iCloud and Apple IDs across your Mac and iOS devices

Use standard formats from .doc, .docx, .png, and .jpeg both for input and output

Manage and organize documents

Who This Book Is For

Developers with a basic knowledge of app development and Swift. You should already know how to use Xcode to create an app. Knowledge of basic Swift syntax is recommended. The book can also be a useful overview and guide to managers who are trying to decide how to convert legacy document-based systems to apps.

Table of Contents

Frontmatter

Chapter 1. Using Documents

Abstract
We use documents to store and organize data in the apps that we use.
Jesse Feiler

Chapter 2. Looking Inside a Document

Abstract
In Chapter 1, you learned how to describe and structure a document. You now know that you, as the designer and developer of an app and its documents, control what data is stored, where and how it is stored, and how to identify and reference it.
Jesse Feiler

Chapter 3. Matching a Document to a Document Format

Abstract
In this chapter, you will see how to match a document as described and defined in your app’s code to an actual runtime document object. This is the heart of putting documents to work. This chapter covers the three basic points you need to address:
Jesse Feiler

Chapter 4. Securing and Protecting Data

Abstract
As soon as you start thinking about saving data, you should be thinking about the security of that data. Every step of the process from deciding what data to store and what rules to implement for safeguarding that data needs to be considered. This chapter focuses on these issues.
Jesse Feiler

Chapter 5. Implementing Documents on macOS: NSDocument

Abstract
The heart of documents on macOS is the NSDocument class. Like UIDocument in iOS, it is an abstract class that you subclass for your own app. Three classes interact to provide document functionality in your app. They are the following:
Jesse Feiler

Chapter 6. Implementing Documents on iOS

Abstract
There are three main issues you have to consider when implementing documents on iOS:
Jesse Feiler

Chapter 7. Implementing Documents on iOS: UIDocument and UIDocumentBrowser ViewController

Abstract
Documents are critical components of many apps and have been so from the beginning of the personal computer era. Many people still think of documents as paper-based objects, but the documents that people work with today on iOS and macOS are much more sophisticated than their paper predecessors. This chapter introduces today’s documents and their structures. It then explains how to use UIDocumentBrowserViewController to manage documents.
Jesse Feiler

Chapter 8. Sharing Documents with Share Buttons

Abstract
In previous chapters, you saw how to implement documents on iOS and macOS to save data and share it across your apps. In this chapter, you’ll see another way to share data using the Share button so that you can dynamically share data from one app to another without using a document to store and share the data.
Jesse Feiler

Chapter 9. Using User Defaults, Settings, and Preferences

Abstract
Documents are the primary way of saving data for apps. You can share the document with various apps and users so that the data is available to all users, but there are other ways to store and manage data in an app. Documents are the workhorses because you can control how much data is saved and how it is saved and shared.
Jesse Feiler

Chapter 10. Working with File Wrappers and Packages

Abstract
This section lets you look at data storage tools other than documents. Like documents, they are all ways to persist data from your apps, and all of these tools, including documents, are supported on Cocoa and Cocoa Touch. Many of the tools (including the ones in this part of the book) have long histories in Cocoa and its predecessors. As noted, documents have evolved over time and have changed in many ways. The tools in this section have certainly changed over time, but the basic structures have remained remarkably stable so they are used in many legacy apps as well as in ones being developed today.
Jesse Feiler

Chapter 11. Using File Archives

Abstract
In Chapter 7, you learned the basics of reading and writing document data. One common way of doing this is to convert your own data from whatever its structure and format is to an NSData object (now a Data object), which can be read or written with a simple statement. The only catch to this is that you need to do the conversion from your data type to Data. One of the simplest and most used techniques is to use the built-in archiving technology in Cocoa.
Jesse Feiler

Backmatter

Additional information

Premium Partner

    Image Credits