Skip to content

Instantly share code, notes, and snippets.

@toshi0383
Last active November 1, 2019 04:05
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 toshi0383/10b2239e15e666beae50c0c242740f41 to your computer and use it in GitHub Desktop.
Save toshi0383/10b2239e15e666beae50c0c242740f41 to your computer and use it in GitHub Desktop.
Generate useful extension when filtering enum values
{% for enum in types.enums %}
// MARK: {{ enum.name }}
extension {{ enum.name }} {
{% for case in enum.cases %}
{{ enum.accessLevel }} var is{{ case.name|upperFirstLetter }}: Bool {
switch self { case .{{ case.name }}: return true; default: return false; }
}
{% endfor %}
}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment