class DiskHelper {
this file will not be backed up to iCloud.
func preventiCloudBackupForFile(filePath:String) {
do {
let url = URL(fileURLWithPath: filePath)
try FileManager.default.addSkipBackupAttributeToItemAtURL(url: url as NSURL)
} catch {
print("Error: \(error)")
}
}
}
FileManager.
extension FileManager{
func addSkipBackupAttributeToItemAtURL(url:NSURL) throws {
try url.setResourceValue(true, forKey: URLResourceKey.isExcludedFromBackupKey)
}
}
. : test.png
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
let url = URL(fileURLWithPath: path)
let filePath = url.appendingPathComponent("test.png").path
DiskHelper().preventiCloudBackupForFile(filePath: filePath)