Bundle+Extension.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // Bundle+Extension.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by mac on 2024/4/10.
  6. //
  7. import UIKit
  8. // MARK: - App的基本信息
  9. public extension Bundle {
  10. // MARK: 2.1、App命名空间
  11. /// App命名空间
  12. static var namespace: String {
  13. guard let namespace = Bundle.main.infoDictionary?["CFBundleExecutable"] as? String else { return "" }
  14. return namespace
  15. }
  16. // MARK: 2.2、项目/app 的名字
  17. /// 项目/app 的名字
  18. static var bundleName: String {
  19. return (Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String) ?? ""
  20. }
  21. // MARK: 2.3、获取app的版本号
  22. /// 获取app的版本号
  23. static var appVersion: String {
  24. return (Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String) ?? ""
  25. }
  26. // MARK: 2.4、获取app的 Build ID
  27. /// 获取app的 Build ID
  28. static var appBuild: String {
  29. return (Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String) ?? ""
  30. }
  31. // MARK: 2.5、获取app的 Bundle Identifier
  32. /// 获取app的 Bundle Identifier
  33. static var appBundleIdentifier: String {
  34. return Bundle.main.bundleIdentifier ?? ""
  35. }
  36. // MARK: 2.7、App 名称
  37. /// App 名称
  38. static var appDisplayName: String {
  39. return (Bundle.main.infoDictionary!["CFBundleDisplayName"] as? String) ?? ""
  40. }
  41. }