Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds Sourcery/Stencil templates to give Swift enum more powers!
Now we have the protocol
EnumClosures
, that when implemented in an enum will create closures for each enum case.Using the following enum as example:
you can implement
EnumClosures
, by doingextension ViewState: EnumClosures
, and Sourcery will generate the following code:There is also the
EnumProperties
that will generate accessors for each case. So using the same enum,ViewState
, you can extendViewState
to useEnumProperties
by doingextension ViewState: EnumProperties
which will generate the following code:And by doing that, we are now able to write such code: