Skip to content

Instantly share code, notes, and snippets.

@benbahrenburg
Created February 19, 2017 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benbahrenburg/ba68bafcded2996e25dbe76bd028b43e to your computer and use it in GitHub Desktop.
Save benbahrenburg/ba68bafcded2996e25dbe76bd028b43e to your computer and use it in GitHub Desktop.
Exclude Specified file url from iCloud backup
struct FileHelpers {
@discardableResult static func addSkipBackupAttribute(url: URL) throws -> Bool {
var fileUrl = url
do {
if FileManager.default.fileExists(atPath: fileUrl.path) {
var resourceValues = URLResourceValues()
resourceValues.isExcludedFromBackup = true
try fileUrl.setResourceValues(resourceValues)
}
return true
} catch {
print("failed setting isExcludedFromBackup \(error)")
return false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment