isTemporary
A Boolean value that indicates whether the identifier is temporary.
Declaration
var isTemporary: Bool { get }Discussion
A temporary identifier is assigned to a model when it is first initialized. Once you call save(), the model receives a permanent identifier.
Temporary identifiers should not be persisted or used to create durable maps to a model. Temporary identifiers are only valid until an object is persisted, and must be remapped to the permanent identifier once a model is saved.
if model.persistentModelID.isTemporary {
try modelContext.save()
}
let data = try JSONEncoder().encode(model.persistentModelID)