Skip to content

Instantly share code, notes, and snippets.

@homerooliveira
Created September 11, 2018 15:22
Show Gist options
  • Save homerooliveira/062e43ccc0a5fb6809e326bc2eb16866 to your computer and use it in GitHub Desktop.
Save homerooliveira/062e43ccc0a5fb6809e326bc2eb16866 to your computer and use it in GitHub Desktop.
CaseIterable template for Sourcery.
// swiftlint:disable all
#if swift(>=4.2)
#else
protocol CaseIterable { }
{% for enum in types.based.CaseIterable|enum %}
{{ enum.accessLevel }} extension {{ enum.name }} {
{% if not enum.hasAssociatedValues %}
static let allCases: [{{ enum.name }}] = [
{% for case in enum.cases %} .{{ case.name }}{% if not forloop.last %},{% endif %}
{% endfor %}]
{% endif %}
}
{% endfor %}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment