Created
March 5, 2018 18:32
-
-
Save samdods/689cf301fb56f1e7a6bc697ae09a0189 to your computer and use it in GitHub Desktop.
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
// | |
// 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