From 65674ad1bb9138b338874d7a713c94a08ad55c86 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 24 Aug 2018 13:55:58 +0300 Subject: [PATCH] fix swift optional date encoding --- Swift/macroses/common.utils.twig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Swift/macroses/common.utils.twig b/Swift/macroses/common.utils.twig index 28ee1b9..46a57a5 100644 --- a/Swift/macroses/common.utils.twig +++ b/Swift/macroses/common.utils.twig @@ -32,7 +32,7 @@ {%- import _self as self -%} {%- if field.type.type.baseTypeName == "DateTime" -%} - ApiDateFormattingService.string(from: {{ self.formatNullableOrOptional(field.name, field.nullable, field.optional) -}}, format: .{{ dateFormatToName(field.type.dateFormat) }}) + ApiDateFormattingService.string(from: {{ field.name -}}, format: .{{ dateFormatToName(field.type.dateFormat) }}) {%- elseif field.type.type.baseTypeName == "Decimal" -%} {{ self.formatNullableOrOptional(field.name, field.nullable, field.optional) -}} .decimalValue @@ -55,8 +55,8 @@ {%- if field.optional -%} try container.encodeIfPresent({{ self.formatEncodingValue(field) }}, forKey: .{{ field.name }}) {%- elseif field.nullable -%} - if let value = {{ self.formatEncodingValue(field) }} { - try container.encode(value, forKey: .{{ field.name }}) + if let {{ field.name }} = {{ field.name }} { + try container.encode({{ self.formatEncodingValue(field) }}, forKey: .{{ field.name }}) } else { try container.encodeNil(forKey: .{{ field.name }}) }