what are the different ways to store files on iOS?
Generated on 7/30/2024
1 search

This post is brought to you by Tailscan,
the best devtool for Tailwind CSS.
There are several ways to store files on iOS, as discussed in various sessions at WWDC:
-
Session Content Directory:
- When using extensions, such as a Lock Screen camera capture extension, you can write data to a provided session content directory. This directory is migrated to your application's container when the extension is dismissed. It is important to persist any data you wish to preserve in this directory (Build a great Lock Screen camera capture experience).
-
PhotoKit:
- For photos and videos, you can use PhotoKit to add captured content directly to the photo library. This is useful for handling permissions and managing media files (Build a great Lock Screen camera capture experience).
-
iCloud and CloudKit:
- For synchronizing data across devices, such as game save data, you can use iCloud and CloudKit. This allows users to continue their progress on different devices seamlessly. CloudKit helps manage syncing and resolving conflicts between local and cloud data (Port advanced games to Apple platforms).
-
Custom Data Stores with SwiftData:
- SwiftData allows you to create custom data stores for different storage formats. For example, you can implement a store that uses a JSON file to persist data. This approach is flexible and can be tailored to specific needs, such as using a custom document format (Create a custom data store with SwiftData).
-
Model Container Customization:
- In iOS 18, SwiftData lets you customize your model container further, including specifying the URL of the data on disk. This allows for more control over where and how data is stored (What’s new in SwiftData).
Relevant Sessions
- Build a great Lock Screen camera capture experience
- Port advanced games to Apple platforms
- Create a custom data store with SwiftData
- What’s new in SwiftData
These methods provide a range of options for file storage on iOS, from using system-provided directories and libraries to implementing custom storage solutions.

What’s new in SwiftData
SwiftData makes it easy to add persistence to your app with its expressive, declarative API. Learn about refinements to SwiftData, including compound uniqueness constraints, faster queries with #Index, queries in Xcode previews, and rich predicate expressions. Join us to explore how you can use all of these features to express richer models and improve performance in your app. To discover how to build a custom data store or use the history API in SwiftData, watch “Create a custom data store with SwiftData” and “Track model changes with SwiftData history”.

Build a great Lock Screen camera capture experience
Find out how the LockedCameraCapture API can help you bring your capture application’s most useful information directly to the Lock Screen. Examine the API’s features and functionality, learn how to get started creating a capture extension, and find out how that extension behaves when the device is locked.

Create a custom data store with SwiftData
Combine the power of SwiftData’s expressive, declarative modeling API with your own persistence backend. Learn how to build a custom data store and explore how to progressively add persistence features in your app. To get the most out of this session, watch “Meet SwiftData” and “Model your schema with SwiftData” from WWDC23.

Evolve your document launch experience
Make your document-based app stand out, and bring its unique identity into focus with the new document launch experience. Learn how to leverage the new API to customize the first screen people see when they launch your app. Utilize the new system-provided design, and amend it with custom actions, delightful decorative views, and impressive animations.

Port advanced games to Apple platforms
Discover how simple it can be to reach players on Apple platforms worldwide. We’ll show you how to evaluate your Windows executable on Apple silicon, start your game port with code samples, convert your shader code to Metal, and bring your game to Mac, iPhone, and iPad. Explore enhanced Metal tools that understand HLSL shaders to validate, debug, and profile your ported shaders on Metal.