Created
October 16, 2019 01:31
-
-
Save foxfriends/12f1a5f2aa41bfdf71c11852420bc8ce to your computer and use it in GitHub Desktop.
Type safe wrapper around a .plist 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
// MARK: - ConfigKey | |
protocol ConfigKey { | |
associatedtype Data | |
static var key: String { get } | |
} | |
// MARK: - Config | |
/// A type safe wrapper around Config.plist | |
enum Config { | |
private static let config: NSDictionary = NSDictionary(contentsOfFile: Bundle.main.path(forResource: "Config", ofType: "plist")!)! | |
static func retrieve<K: ConfigKey>(_ key: K.Type) -> K.Data { config.object(forKey: K.key) as! K.Data } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment