Skip to content

Instantly share code, notes, and snippets.

@egabor
Last active February 14, 2022 20:57
Show Gist options
  • Save egabor/24398ac197c78f2f15e96e5b4a6da31a to your computer and use it in GitHub Desktop.
Save egabor/24398ac197c78f2f15e96e5b4a6da31a to your computer and use it in GitHub Desktop.
General App Configuration File
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
}
}
// MARK: - Genaral App Configuration
BUNDLE_ID = <#BUNDLE_ID#>
APP_NAME = <#APP_NAME#>
// MARK: - API Connection
BASE_URL = <#BASE_URL#>
API_SECRET = <#API_SECRET#>
<?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>
.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