How to create a SwiftData model variable that does not persist

Oscar de la Hera Gomez
Three flowers that represent Swift, SwiftData and Xcode side by side. Beneath them sits the text "Transient Values."

To tell SwiftData that a variable should not persist and always start at a default value on launch, use the @Transient annotation.

Step One: Create a SwiftData model

A screenshot of Xcode showing a completed model in the SampleSwiftDataModel.swift file.

Consult the tutorial below to learn how to setup a SwiftData model.

Step Two: Create a Transient Variable

A screenshot of Xcode showing a struct that uses the codable protocol.

Add the new variable that you wish not to persist, set its default value and mark it with an @Transient annotation.

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.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details