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.

Explore Swift performance
Discover how Swift balances abstraction and performance. Learn what elements of performance to consider and how the Swift optimizer affects them. Explore the different features of Swift and how they’re implemented to further understand the tradeoffs available that can impact performance.

Consume noncopyable types in Swift
Get started with noncopyable types in Swift. Discover what copying means in Swift, when you might want to use a noncopyable type, and how value ownership lets you state your intentions clearly.

What’s new in SwiftData
SwiftData makes it easy to add persistence to your app with its expressive, declarative API. Learn about refinements to SwiftData, including compound uniqueness constraints, faster queries with #Index, queries in Xcode previews, and rich predicate expressions. Join us to explore how you can use all of these features to express richer models and improve performance in your app. To discover how to build a custom data store or use the history API in SwiftData, watch “Create a custom data store with SwiftData” and “Track model changes with SwiftData history”.