Last active
February 14, 2022 20:57
-
-
Save egabor/24398ac197c78f2f15e96e5b4a6da31a to your computer and use it in GitHub Desktop.
General App Configuration File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Logging | |
enum ConfigKey: String { | |
case bundleId = "BUNDLE_ID" | |
case appName = "APP_NAME" | |
case baseUrl = "BASE_URL" | |
case apiSecret = "API_SECRET" | |
case appVersion = "CFBundleShortVersionString" | |
case appBuild = "CFBundleVersion" | |
} | |
class Config { | |
// MARK: - Plist | |
private static let infoDictionary: [String: Any] = { | |
guard let dict = Bundle.main.infoDictionary else { | |
return [:] | |
} | |
return dict | |
}() | |
// MARK: - Plist values | |
var bundleId: String { | |
value(for: .bundleId) | |
} | |
var appName: String { | |
value(for: .appName) | |
} | |
var baseUrl: String { | |
value(for: .baseUrl) | |
} | |
var apiSecret: String { | |
value(for: .apiSecret) | |
} | |
var appVersion: String { | |
value(for: .appVersion) | |
} | |
var appBuild: String { | |
value(for: .appBuild) | |
} | |
private func value(for key: ConfigKey) -> String { | |
guard let value = Config.infoDictionary[key.rawValue] as? String else { | |
print("💥 [\(key.rawValue)] is not set in plist file.") | |
return "" | |
} | |
return value | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Genaral App Configuration | |
BUNDLE_ID = <#BUNDLE_ID#> | |
APP_NAME = <#APP_NAME#> | |
// MARK: - API Connection | |
BASE_URL = <#BASE_URL#> | |
API_SECRET = <#API_SECRET#> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>BUNDLE_ID</key> | |
<string>$(BUNDLE_ID)</string> | |
<key>APP_NAME</key> | |
<string>$(APP_NAME)</string> | |
<key>BASE_URL</key> | |
<string>$(BASE_URL)</string> | |
<key>API_SECRET</key> | |
<string>$(API_SECRET)</string> | |
</dict> | |
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.package(url: "https://github.com/apple/swift-log.git", .exact("1.4.2")) | |
//.product(name: "Logging", package: "swift-log") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment