diff --git a/Swift/Class.swift.twig b/Swift/Class.swift.twig index f8b9ad5..748c4a1 100644 --- a/Swift/Class.swift.twig +++ b/Swift/Class.swift.twig @@ -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 -%} \ No newline at end of file diff --git a/Swift/blocks/class/fields-hash.twig b/Swift/blocks/class/fields-hash.twig new file mode 100644 index 0000000..f43a49c --- /dev/null +++ b/Swift/blocks/class/fields-hash.twig @@ -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 -%} \ No newline at end of file