![]() ![]() And this is all there is to loading and saving a document. Note that while the save operation is asynchronous, reading is expected to complete by the time the method returns. This is great if you want to store your documents in a database or have special requirements for reading and writing your document. Now, if you want total control, overriding 'saveToURL:forSaveOperation:' and 'readFromURL:' instead gives you full access to the URL and leaves all reading and writing to you. ![]() For example here, the document deals with regular markdown files, so we expect a data object. To learn more about file types and how they work, check out the Tech Talk 'Uniform Type Identifiers - a reintroduction'. The content of the document is a Data object for regular files, or a FileWrapper for everything else. When the document is being saved, 'contentsForType:' is called to get the current content of the document. When a document gets opened, 'loadFromContents:ofType:' will be called with the contents of the file. For simple, file based documents, there are two convenience methods you can override. Before we talk more about accessing the content, let's talk about loading and saving. For example, a document model for a markdown editor might only have a single text property or it could expose a more complex interface that allows updating individual parts of the document. Accessing the content is more specific to the type of document and how it is used in your app. Loading and saving is very similar across all documents. When implementing a UIDocument subclass, there are two main responsibilities to take care of: loading and saving of the document, and providing access to the content of the document. For this reason, UIDocument is thread safe and takes care of coordinating access through locks and queues. UIDocument's load and save operations are asynchronous, which allows for lengthy read and write operations, if necessary. Files on disk are the most common, but you can also save and load your documents using a database and a custom URL scheme. It's an abstract base class that is meant to be subclassed for each file-type that your app supports. The core of every document based app is UIDocument. At the end I explore some best practices to migrate your existing apps to take advantage of UIDocument. I'll then explain which features are built-in, and how to customize them further. In this video, you will learn how to use UIDocument and how to present documents with UIDocumentViewController. This enables features like sharing, dragging the document, undo and redo support, and more. It works together with UIDocument to automatically configure the navigation bar. UIDocumentViewController is a new base class for content view controllers. To learn more about the SwiftUI side of this, check out 'Build document-based apps in SwiftUI' from WWDC20 and 'SwiftUI on iPad: Add toolbars, titles, and more' from WWDC22. To catch up on desktop-class iPad APIs, check out 'Meet desktop-class iPad' and 'Build a desktop-class iPad app' from WWDC22.įor SwiftUI development, DocumentGroup now has support for all these features with no additional code. You get great system defaults, but can customize any individual behavior. This new view controller is built in a modular way. It works nicely together with the desktop-class iPad APIs introduced in iPadOS 16, and the existing document-centric APIs. ![]() iPadOS 17 introduces a new view controller that automatically enables a large number of features in your app. This video focuses on improvements to viewer and editor apps, but some of the content discussed also applies to browser apps. Those that allow browsing documents, such as the Files app those that allow viewing content, for example Quick Look and those that also allow editing or creating content, like Pages, Keynote, or Numbers. There are three types of document-centric apps. Document-centric apps are a big part of productivity tools, especially on the iPad. I'm Michael Ochs and in this video I'm going to talk about how to build better document-centric apps.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |