I have one Swift Codable model like that:
public struct model: Codable {
public let id: String
public let title: String
public var _tag: MyTag? = MyTag.defaultValue
}
The API JSON not contains _tag field.
And I set _tag
to default value and change/check it later in client side.
I'm pretty sure that field could not be nil. However if remove '?' mark of public var _tag: Tag?
. Moya JSONDecoder report that error:
Swift.DecodingError.keyNotFound
.
Any workaround to set that field with default value without Optional type and also could decode from JSON without any error?
Thanks.