question: how to combine keys of multiple dictionaries in a single list and remove duplicates
Opened this issue · 0 comments
claire-lynch-okcupid commented
hello swiftgen team!
i am working with stencil in the context of a custom swiftgen template.
i am attempting to iterate over a list of dictionaries and extract all the unique keys which will then represent the cases of an enum.
something like this:
{% macro extractUniqueKeys dictionaries %}
public enum AnalyticsPropertyKey: String {
{% for dict in dictionaries %}
{% for key,value in dict %}
// Only want to execute setting key name and declaring case if I haven't already found that key!
{% set keyName %}{{key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}{% endset %}
case {{keyName}} = "{{key}}"
{% endfor %}
{% endfor %}
}
{% endmacro %}
Is there a way to do this? I also asked on the stencil repo, in case that's the better forum. thank you!