AppConstants.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // LoopFollow
  2. // AppConstants.swift
  3. import Foundation
  4. // Class that contains general constants used in different classes
  5. class AppConstants {
  6. /// Extracts the app suffix from the bundle identifier
  7. /// Bundle identifier format: com.$(unique_id).LoopFollow$(app_suffix)
  8. /// Returns the suffix part (e.g., "2" for "com.example.LoopFollow2")
  9. static var appSuffix: String {
  10. guard let bundleId = Bundle.main.bundleIdentifier else {
  11. return ""
  12. }
  13. // Extract suffix from bundle identifier
  14. // Pattern: com.$(unique_id).LoopFollow$(app_suffix)
  15. let pattern = "LoopFollow(.+)$"
  16. if let regex = try? NSRegularExpression(pattern: pattern) {
  17. let range = NSRange(location: 0, length: bundleId.utf16.count)
  18. if let match = regex.firstMatch(in: bundleId, options: [], range: range) {
  19. let suffixRange = match.range(at: 1)
  20. if let swiftRange = Range(suffixRange, in: bundleId) {
  21. let suffix = String(bundleId[swiftRange])
  22. return suffix.isEmpty ? "" : "_\(suffix)"
  23. }
  24. }
  25. }
  26. return ""
  27. }
  28. /// Returns a unique identifier for this app instance based on the app suffix
  29. static var appInstanceId: String {
  30. return "LoopFollow\(appSuffix)"
  31. }
  32. }