Skip to content

Instantly share code, notes, and snippets.

@hishd
Created March 27, 2024 06:29
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 hishd/e37ccf2f090d7aa10359ae1f95ac76b4 to your computer and use it in GitHub Desktop.
Save hishd/e37ccf2f090d7aa10359ae1f95ac76b4 to your computer and use it in GitHub Desktop.
import Foundation
@dynamicMemberLookup
struct AppConfig {
let weatherApiKey: String = ""
private init() {}
static subscript<T>(dynamicMember keyPath:KeyPath<AppConfig, T>) -> T {
AppConfig()[keyPath: keyPath]
}
}
//MARK: Accessing the data (Autocomplete does not work due to dynamicMemberLookup)
let key = AppConfig.weatherApiKey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment