Skip to content

Instantly share code, notes, and snippets.

@hhanesand
Last active December 16, 2020 00:23
Show Gist options
  • Save hhanesand/ff9db875ca3e7a13dc727b375d6cf84e to your computer and use it in GitHub Desktop.
Save hhanesand/ff9db875ca3e7a13dc727b375d6cf84e to your computer and use it in GitHub Desktop.
<%_
import SourceryRuntime
let ConvertibleTypes = types.implementing["KeyPathConvertible"]
-%>
<%_ for Convertible in types.implementing["KeyPathConvertible"] { -%>
extension PartialKeyPath where Root == <%= Convertible.name %> {
var stringValue: String {
switch self {
<%_ for member in Convertible.variables { -%>
case \<%= Convertible.name %>.<%= member.name %>: return "<%= member.name %>"
<%_ } -%>
default: fatalError("Unexpected key path")
}
}
}
<%_ } -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment