Skip to content

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

@claire-lynch-okcupid

Description

@claire-lynch-okcupid

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions