Skip to content

Instantly share code, notes, and snippets.

@samdods
Created March 5, 2018 18:32
Show Gist options
  • Save samdods/689cf301fb56f1e7a6bc697ae09a0189 to your computer and use it in GitHub Desktop.
Save samdods/689cf301fb56f1e7a6bc697ae09a0189 to your computer and use it in GitHub Desktop.
//
// Config.swift
// Analytics
//
public protocol AnalyticsConfig {
static var analyticsKey: String { get }
static var appVersion: String { get }
}
/// Use this method to inject the configuration for this framework.
public func setup(with config: AnalyticsConfig.Type) {
ConfigType.shared = ConfigType(config)
}
var Config: ConfigType { // swiftlint:disable:this variable_name
if let config = ConfigType.shared {
return config
} else {
fatalError("Please set the Config for \(Bundle(for: ConfigType.self))")
}
}
final class ConfigType {
static fileprivate var shared: ConfigType?
let analyticsKey: String
let appVersion: String
fileprivate init(_ config: AnalyticsConfig.Type) {
self.analyticsKey = config.analyticsKey
self.appVersion = config.appVersion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment