How to add complex values to SwiftData models
![Oscar de la Hera Gomez](https://www.delasign.com/CDN/headshots/profile.webp)
![Three flowers that represent Swift, SwiftData and Xcode. Beneath them sits the text "Complex Values."](https://www.delasign.com/CDN/images/How-to-add-complex-values-to-SwiftData-models.webp)
To include complex values such as structures, enumerations or other value types to a SwiftData model, make sure that they conform to the Codable protocol.
Step One: Create the Model
![A screenshot of Xcode showing a completed model in the SampleSwiftDataModel.swift file.](https://www.delasign.com/CDN/images/Complete-Model.webp)
Consult the tutorial below to learn how to setup a SwiftData model.
Step Two: Create the Complex Value
![A screenshot of Xcode showing a struct that uses the codable protocol.](https://www.delasign.com/CDN/images/Create-Struct_2023-10-27-153655_wfcb.webp)
Create a new struct, enumeration or complex value and make sure that it uses the Codable protocol.
Step Three: Add to the SwiftData Model
![A screenshot of Xcode showing how we added a complex value to the model and init function.](https://www.delasign.com/CDN/images/Add-to-Model.webp)
Add the complex value to the SwiftData model and init function.
If you do not wish for the value to persist, add a @Transient annotation and a default value.
Looking to learn more about things you can do with SwiftData, Swift or XCode ?
Consult our quick start guide or search our blog to find educational content on learning how to use SwiftData, Swift or XCode.