Created
April 18, 2020 08:13
-
-
Save martinhoeller/4bf05d5a647cd465d736d319e17b2bec to your computer and use it in GitHub Desktop.
A URL extension to insert a timestamp in the URL's file name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension URL { | |
// Inserts a timestamp into a URL's filename | |
// e.g. "/path/to/file.ext" -> "/path/to/file~1587197384.ext" | |
func addingTimestamp(separator: String = "~") -> URL { | |
let timestamp = Int(Date().timeIntervalSince1970) | |
let filename = deletingPathExtension().lastPathComponent + "\(separator)\(timestamp).\(pathExtension)" | |
return deletingLastPathComponent().appendingPathComponent(filename) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment