Prevent your app's files from being included in iCloud Backup

I am a Software Engineer working on open source and enterprise mobile SDKs for iOS and MacOS developers written in Swift. From 🇩🇪 and happily living in 🇺🇸
Search for a command to run...

I am a Software Engineer working on open source and enterprise mobile SDKs for iOS and MacOS developers written in Swift. From 🇩🇪 and happily living in 🇺🇸
No comments yet. Be the first to comment.
WWDC26 kicked off on June 8, 2026. The information in this article reflects the information published by Apple on that date. There are 14 new frameworks. Name Description AccessoryAccess Manage

WWDC25 kicked off on June 9, 2025. The information in this article reflects the information published by Apple on that date. New Frameworks NameDescription AlarmKitSchedule prominent alarms and countdowns to help people manage their time. AVR...

WWDC25 is almost here, and I couldn’t be more excited! Whether you're attending the official events, community meetups, or just soaking in the energy around Cupertino, there’s no better time to connect, share ideas, and celebrate everything we love a...

In this blog post, I’ll share an observation and advice regarding the caching behavior of network responses by Apple’s APIs. If you are unfamiliar with caching of network responses then I recommend Apple’s article Accessing cached data that introduce...
WWDC24 kicked off on June 10, 2024. The information in this article reflects the information published by Apple on that date. New Frameworks NameDescription AccessorySetupKitUse AccessorySetupKit to discover accessories with Bluetooth or Wi-Fi...

In this blog post, you will learn which files of your app are automatically included in a Backup (iTunes or iCloud) and how to exclude specific files.
This is important to know if you want to prevent sensitive data from being backed up by Apple's iCloud service. Also, you want to reduce the space and time that backups take to create.
Golden rule: any file that can be re-created or downloaded should be excluded from the backup. This is particularly important for large media files.
An iOS app can create and save files in various directories of its app data container.
There are four major directories.
| Directory | Type of Files to be stored | Part of iCloud Backup Data |
| Documents | User-visible files | Yes |
| /Library | Top-level directory for any files that are not user data files | Yes with the exception of the Caches subdirectory |
| /Library/Application Support | App-created support files | Yes |
| /Library/Caches | Purgeable or transient content needed longer than temporary data, but not as long as a support file | No |
| /tmp | Temporary data | No |
The iOS system will create all those directories except for Library/Application Support and therefore you would need to create the directory if you need it.
let appSupportDir = URL.applicationSupportDirectory
if !FileManager.default.fileExists(atPath: appSupportDir.path()) {
try? FileManager.default.createDirectory(at: appSupportDir, withIntermediateDirectories: true)
}
iOS 16 provides convenient APIs to get URL s' for such directories but if you have to support lower iOS versions then check out this dependency-free Swift package that provides a backport of those APIs.
Back to the topic.
You can exclude directories & files from the backup by setting isExcludedFromBackup resource value.
var newFile = URL.documentsDirectory.appending(path: "News.txt")
try "Hello, World!".write(to: newFile, atomically: true, encoding: .utf8)
var resource = URLResourceValues()
resource.isExcludedFromBackup = true
try newFile.setResourceValues(resource)
This property is only useful for excluding cache and other application support files which are not needed in a backup. Some operations commonly made to user documents will cause this property to be reset to false and so this property should not be used on user documents.
The
isExcludedFromBackupresource value exists only to provide guidance to the system about which files and directories it can exclude; it’s not a mechanism to guarantee those items never appear in a backup or on a restored device.
Because certain file operations can reset resource values, make sure you set an excluded file’s resource values each time you save it.
Note that I called setResourceValues after the file got created. You cannot call setResourceValues before the actual file exists on the file system. Otherwise, an error gets thrown.
You can create an extension on URL for convenience.
extension URL {
mutating func excludeFromBackup() throws {
var resource = URLResourceValues()
resource.isExcludedFromBackup = true
try self.setResourceValues(resource)
}
}
The code usage becomes much simpler:
var newFile = URL.documentsDirectory.appending(path: "News.txt")
try? "Hello, World!".write(to: newFile, atomically: true, encoding: .utf8)
newFile.excludeFromBackup()
Furthermore:
To indicate the system can exclude a group of related files from iCloud Backup, move those files into a directory and update the directory’s isExcludedFromBackup resource value.
If you create an excludable directory inside the app container’s Library then consider naming the directory with the app’s bundle identifier to avoid potential conflicts with directories the system may create in the future.
If you want to deepen your knowledge about iOS Storage and best practices then I recommend the following Apple Tech Talk:
Additionally, I recommend reading Apple's article Optimizing Your App’s Data for iCloud Backup.