Skip to content

Instantly share code, notes, and snippets.

@Maschina
Created June 13, 2021 10:34
Show Gist options
  • Save Maschina/f69532eab2a71217d749c13070090bdd to your computer and use it in GitHub Desktop.
Save Maschina/f69532eab2a71217d749c13070090bdd to your computer and use it in GitHub Desktop.
Get compilation time in Swift. Credits go to Alain. T (https://stackoverflow.com/a/38421481/873072)
/// Get the build date and time
var compileTime: Date {
let bundleName = Bundle.main.infoDictionary!["CFBundleName"] as? String ?? "Info.plist"
if let infoPath = Bundle.main.path(forResource: bundleName, ofType: nil),
let infoAttr = try? FileManager.default.attributesOfItem(atPath: infoPath),
let infoDate = infoAttr[FileAttributeKey.creationDate] as? Date
{ return infoDate }
return Date()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment