add Equatable protocol conformance

Hashable in progress
This commit is contained in:
Ivan Smolin 2017-06-30 19:10:48 +03:00
parent 67b5fe0809
commit d944d4d5ee
2 changed files with 31 additions and 0 deletions

View File

@ -37,3 +37,13 @@ import ObjectMapper
}
}
{% if not hasChilds %}
extension {{ type.baseTypeName }}: Equatable {
static func ==(lhs: {{ classType }}, rhs: {{ classType }}) -> Bool {
return {%- for field in allFieldsOrdered %} lhs.{{ field.name }} == rhs.{{ field.name }} {% if not (loop.last) -%} && {%- endif %}
{% endfor %}
}
}
{% endif -%}

View File

@ -0,0 +1,21 @@
{%- import '../../macroses/common.utils.twig' as utils -%}
{%- macro hashOf(name, type, optional, nullable, ) -%}
{%- if type.baseTypeName == "Array" -%}
{#- implement hash for Array -#}
{%- elseif type.baseTypeName == "Map" -%}
{#- implement hash for Map -#}
{%- else -%}
{#- implement hash for regular value -#}
{%- endif -%}
{%- endmacro -%}
{%- for field in fields %}
{#- FIXME: Value of type '[T]' has no member 'hashValue'} -#}
{#- FIXME: The same for [TKey: TValue] -#}
{%- if field.optional or field.nullable %}
({{ field.name }}?.hashValue ?? 0)
{%- else %}
{{ field.name }}.hashValue
{%- endif -%}
{% if not (loop.last) %} ^ {%- endif %}
{%- endfor -%}