If a Swift Type is Codable but has more properties than the JSON type. What happens?

Asked on 08/05/2024

1 search

When a Swift type is Codable but has more properties than the JSON type, the additional properties in the Swift type are simply ignored during the decoding process. The JSON decoder will only map the properties that are present in the JSON data to the corresponding properties in the Swift type. Any properties in the Swift type that do not have a corresponding key in the JSON data will remain at their default values.

For more details on Swift's performance and handling of types, you can refer to the session Explore Swift performance.