Skip to content

Instantly share code, notes, and snippets.

@rkotzy
Created March 1, 2019 18:55
Show Gist options
  • Save rkotzy/35c54e6d44f4b427ac03712688a4de84 to your computer and use it in GitHub Desktop.
Save rkotzy/35c54e6d44f4b427ac03712688a4de84 to your computer and use it in GitHub Desktop.
Determine what environment your iOS app is running in
import Foundation
enum AppConfiguration : String {
case debug = "debug"
case testFlight = "testFlight"
case appStore = "appStore"
}
struct Config {
// 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 appConfiguration: AppConfiguration {
if isDebug {
return .debug
} else if isTestFlight {
return .testFlight
} else {
return .appStore
}
}
}
// // Sample usage
// if Config.appConfiguration != .appStore {
// // this is a test user
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment