36 lines
832 B
Swift
36 lines
832 B
Swift
enum Environment {
|
||
case development
|
||
case production
|
||
}
|
||
|
||
struct AppConfig {
|
||
static var current: Environment = {
|
||
#if DEBUG
|
||
return .development
|
||
#else
|
||
return .production
|
||
#endif
|
||
}()
|
||
|
||
static var baseURL: String {
|
||
switch current {
|
||
case .development:
|
||
return "https://dev-api.yourdomain.com/v1"
|
||
case .production:
|
||
return "https://api.yourdomain.com/v1"
|
||
}
|
||
}
|
||
|
||
// 添加更多环境变量
|
||
static var analyticsKey: String {
|
||
switch current {
|
||
case .development: return "dev_analytics_key"
|
||
case .production: return "prod_analytics_key"
|
||
}
|
||
}
|
||
|
||
// 运行时切换环境(用于测试)
|
||
static func switchEnvironment(to env: Environment) {
|
||
current = env
|
||
}
|
||
} |