VersionInfo.swift (1031B)
1 // 2 // VersionInfo.swift 3 // damus 4 // 5 // Created by William Casarin on 2023-08-01. 6 // 7 8 import Foundation 9 10 11 class VersionInfo { 12 private static var _version: String? = nil 13 14 static var version: String { 15 if let _version { 16 return _version 17 } 18 19 guard let short_version = Bundle.main.infoDictionary?["CFBundleShortVersionString"], 20 let bundle_version = Bundle.main.infoDictionary?["CFBundleVersion"] 21 else { 22 return "Unknown" 23 } 24 25 // we only have these in debug builds 26 let hash = git_hash ?? "" 27 let ver = "\(short_version) (\(bundle_version)) \(hash)" 28 29 _version = ver 30 return ver 31 } 32 33 static var git_hash: String? { 34 if let url = Bundle.main.url(forResource: "build-git-hash", withExtension: "txt"), 35 let content = try? String(contentsOf: url, encoding: .utf8) { 36 return content.trimmingCharacters(in: .whitespacesAndNewlines) 37 } else { 38 return nil 39 } 40 } 41 }