Skip to content

Instantly share code, notes, and snippets.

@KiGi
Created May 7, 2015 22:17
Show Gist options
  • Save KiGi/1be0197d9ef4ddfc9970 to your computer and use it in GitHub Desktop.
Save KiGi/1be0197d9ef4ddfc9970 to your computer and use it in GitHub Desktop.
Swift 1.2 fileExistsAtPath
func checkIfFileExpired( fileURL : NSURL ) -> Bool {
let fileManager = NSFileManager()
if let fileManager.fileExistsAtPath(fileURL) {
var error : NSError? = nil
if let filePath = fileURL.path,
let fileAttr = fileManager.attributesOfItemAtPath(filePath, error: &error),
let creationDate = fileAttr[NSFileModificationDate] as? NSDate {
return creationDate.isBefore(NSDate.oneDayAgo())
} else {
println("problem examining file attributes for \(fileURL): error was \(error)")
}
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment