Chapter 8. Working with Files in iCloud
In this chapter, we’ll discuss working with documents in iCloud on iOS. File management in iOS is handled by the apps themselves, rather than by a system-provided app like the Finder. As a result, we need to take care of tasks like providing a list of all available files to the user, opening the files, and saving changes.
This means that, when you work with documents in iOS, you need to do quite a bit more work. While you still have built-in automatic saving, you need to manually open and close documents; additionally, because bindings don’t exist on iOS, you need to manually update the contents of the document object whenever the user provides input.
We’ll start by listing whatever’s already in iCloud, to demonstrate that we’ve got access to the same container as the Mac app and also to provide what will eventually become the user interface for opening these documents. Next, we’ll implement the
Document class, which is the iOS counterpart of the Mac app’s
Document class. Finally, we’ll add support for creating new documents.
The App Sandbox
Apps on iOS are extremely limited in terms of the files that they’re allowed to access. Any app that you install via the App Store—which means any third-party app—is sandboxed: the system will only permit it to read and write files in a single folder. This keeps any other app from reaching into the app’s files and prevents your app from poking around the user’s other files. The goal is to preserve user ...