Skip to content

Instantly share code, notes, and snippets.

@foxfriends
Created October 16, 2019 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxfriends/12f1a5f2aa41bfdf71c11852420bc8ce to your computer and use it in GitHub Desktop.
Save foxfriends/12f1a5f2aa41bfdf71c11852420bc8ce to your computer and use it in GitHub Desktop.
Type safe wrapper around a .plist file
// 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