Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question: how to combine keys of multiple dictionaries in a single list and remove duplicates #337

Open
claire-lynch-okcupid opened this issue Mar 20, 2023 · 0 comments

Comments

@claire-lynch-okcupid
Copy link

claire-lynch-okcupid commented Mar 20, 2023

hello stencil 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 swiftgen repo, too, in case that's the better forum. thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant