Last active
December 16, 2020 00:23
-
-
Save hhanesand/ff9db875ca3e7a13dc727b375d6cf84e to your computer and use it in GitHub Desktop.
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
<%_ | |
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