Skip to content

Instantly share code, notes, and snippets.

@ekscrypto
Last active May 18, 2022 12:43
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 ekscrypto/4e289f5bccaeaabf78b761266e6ddf56 to your computer and use it in GitHub Desktop.
Save ekscrypto/4e289f5bccaeaabf78b761266e6ddf56 to your computer and use it in GitHub Desktop.
RawRepresentable ~ prefix
enum AppStorageKeys: String {
case activeEnvironment
}
extension RawRepresentable {
/// ~
///
/// Convenience operator to allow ~something instead of something.rawValue
static prefix func ~(rhs: Self) -> Self.RawValue {
rhs.rawValue
}
}
// Typical way of extracting String value from enum
let myEnvironmentKey: String = AppStorageKeys.activeEnvironment.rawValue
// Using the prefix
let myEnvironmentKey: String = ~AppStorageKeys.activeEnvironment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment