Merge pull request #48 from TouchInstinct/feature/swift_copy_without

add copyWithout method to classes
This commit is contained in:
Ivan Smolin 2018-10-30 16:07:00 +03:00 committed by GitHub
commit e2568de3cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -83,6 +83,10 @@ extension {{ type.baseTypeName }} {
return {{ type.baseTypeName }}({%- include 'blocks/class/fields-optional-initialization.twig' with { fields: allFieldsOrdered } -%})
}
func copy{%- if hasChilds -%}{{ type.baseTypeName }}{%- endif -%}Without({%- include 'blocks/class/bool-parameters-fields.twig' with { fields: allFieldsOrdered } -%}) -> {{ type.baseTypeName }} {
return {{ type.baseTypeName }}({%- include 'blocks/class/fields-without-initialization.twig' with { fields: allFieldsOrdered } -%})
}
}
{{ "\n" }}
{%- endif -%}

View File

@ -0,0 +1,7 @@
{%- import '../../macroses/common.utils.twig' as utils -%}
{%- if fields is not empty -%}
{%- for field in fields -%}
{{ field.name }}: Bool = false{%- if not (loop.last) %}, {% endif %}
{%- endfor -%}
{%- endif -%}

View File

@ -0,0 +1,7 @@
{%- import '../../macroses/common.utils.twig' as utils -%}
{%- if fields is not empty -%}
{%- for field in fields -%}
{{ field.name }}: {{ field.name }} ? {{ utils.defaultValueForField(field) }} : self.{{ field.name }}{%- if not (loop.last) %}, {% endif %}
{%- endfor -%}
{%- endif -%}