I worked great with Swift 1.2 since I used filePath as a string. Now Swift 2 wants us all to use the URL paths, I can't get this to work even if I read their documents.
I have:
var fileName = "myRespondusCSV.csv"
let fileManager = NSFileManager.defaultManager()
let documentsURL = fileManager.URLsForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask)
if let documentPath: NSURL = documentsURL.first as NSURL! {
filePath = documentPath.URLByAppendingPathComponent(fileName)
print(filePath)
} else {
fileManager.createFileAtPath(filePath!.path!,
contents: ("" as String).dataUsingEncoding(NSUTF8StringEncoding)!,
attributes:nil)
print("file has been created")
}
}
func excludeFileFromBackup() {
var error:NSError?
var fileToExcludeh = fileURLWithPath(filePath)
let success = fileToExcludeh.setResourceValue(true, forKey: NSURLIsExcludedFromBackupKey, error: &error)
}
I get 'Using Unresolved Identifier' fileURLWithPath '!
Should I use an absolute url?
source
share