Bundle+Sweeter.swift 777 B

12345678910111213141516171819202122232425
  1. //
  2. // Bundle+Sweeter.swift
  3. //
  4. // Created by Yonat Sharon on 2019-02-08.
  5. //
  6. import Foundation
  7. public extension Bundle {
  8. /// Sweeter: app name with reasonable fallback to process name
  9. var name: String {
  10. return infoDictionary?["CFBundleDisplayName"] as? String
  11. ?? infoDictionary?["CFBundleName"] as? String
  12. ?? ProcessInfo.processInfo.processName
  13. }
  14. /// Sweeter: app name, version, and build number
  15. var infoString: String {
  16. let version = infoDictionary?["CFBundleShortVersionString"] as? String
  17. let build = infoDictionary?["CFBundleVersion"] as? String
  18. let nameAndVersion = [name, version].compact.joined(separator: " ")
  19. return [nameAndVersion, build].compact.joined(separator: " #")
  20. }
  21. }