Document-Based Apps Tutorial: Getting Started
In this document-based app tutorial, you will explore how you can save and open custom documents and interact with the Files app. By Warren Burton.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Document-Based Apps Tutorial: Getting Started
35 mins
- Introduction
- Getting Started
- Archiving and De-archiving Data
- Saving and Loading Your Composition
- Working With the Document Browser
- Creating a UIDocument Subclass
- Encoding the Document
- Decoding the Document
- Installing UIDocumentBrowserViewController
- Presenting a Container View Controller
- Configuring UIDocumentBrowserViewController
- Configuring Info.plist
- Responding to UIDocumentBrowserViewController Delegate Actions
- Creating Documents
- Importing Documents
- Opening Documents
- Transitioning to the Markup Editor
- Opening a MarkupDocument From a URL
- Supplying DocumentBrowserDelegate With a Presentation Closure
- Allowing Other Apps to Open Documents
- Setting Up the App Delegate
- Updating DocumentBrowserViewController
- Updating RootViewController
- Updating AppDelegate
- Providing a Custom Document Icon
- Adding a ThumbnailProvider Extension Target
- Configuring a QLThumbnailProvider Subclass
- Configuring the Info.plist
- Linking the Framework
- Where to Go From Here?
Linking the Framework
The last thing to do is to link the MarkupFramework to the extension:
- Expand the Products folder in the Project navigator.
- Select MarkupFramework.framework.
- Add a check to MarkupThumbnail in the Target Membership of the file inspector.
You may need to set your run target back to Markup after adding the Thumbnail Provider extension.
Build and run. Wait a few seconds for the extension to boot and do its work. The icons should turn into baby representations of the content:
Pretty cool, right?
Where to Go From Here?
Congratulations! You have built a document-based app using the system file browser. You can find a reference finished project via the Download Materials link at the top or bottom of this tutorial.
In this tutorial, you’ve learned how to:
- Create a UIDocument subclass.
- Configure file properties and UTI’s.
- Interact with the system file browser component.
- Handle interactions with other apps.
- Supply a dynamically generated icon.
The advantage of this component is that everyone who uses this interface will recognize it as a file system. You can share these documents and put them on your iCloud drive for editing on any of your devices. If you’re upgrading an existing code base, and can drop iOS 10 support, now might be a good time to delete some code and replace it with this component.
Some areas for further research:
-
NSFilePresenter is the core protocol that
UIDocument
adopts to interact with the file system. - QLPreviewingController is the class you need to implement to make a Quicklook Preview Extension.
- WWDC 2017 Session 229 gives an overview of this topic. It covers more advanced concepts, too.
I look forward to hearing about your adventures with UIDocumentBrowserViewController and its friends in the forum below!