Skip to content

Instantly share code, notes, and snippets.

@cafielo
Created February 27, 2021 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cafielo/061c3c940095203b1f216218c5c47b36 to your computer and use it in GitHub Desktop.
Save cafielo/061c3c940095203b1f216218c5c47b36 to your computer and use it in GitHub Desktop.
Env Configuration
enum Env: String {
case debug
case testFlight
case appStore
}
struct App {
struct Folders {
static let documents: NSString = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString
static let temporary: NSString = NSTemporaryDirectory() as NSString
}
static let version: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
static let build: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as! String
// This is private because the use of 'appConfiguration' is preferred.
private static let isTestFlight = Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
// This can be used to add debug statements.
static var isDebug: Bool {
#if DEBUG
return true
#else
return false
#endif
}
static var env: Env {
if isDebug {
return .debug
} else if isTestFlight {
return .testFlight
} else {
return .appStore
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment