I try to write code which changes property of file, but I get a compiler error.
Here is the code:
func addSkipBackupAttributeToItemAtURL(URL: NSURL) -> Bool{
let fileManager = NSFileManager.defaultManager()
assert(fileManager.fileExistsAtPath(URL.absoluteString))
var error:NSError?
let success:Bool = try? URL.setResourceValue(NSNumber(bool: true),forKey: NSURLIsExcludedFromBackupKey)
if !success {
print("Error excluding (URL.lastPathComponent) from backup (error)")
} else {
print("File at path (URL) was succesfully updated")
}
return success
}
and the error is:
Cannot convert value of type '()?' to specified type 'Bool'
How can I fix it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…