Post

Replies

Boosts

Views

Activity

SwiftData looses attribute when restarting app
I'm trying to archive some data in my SwiftUI app, using SwiftData. I implemented a Archive Model: import Foundation import SwiftData @Model class ArchiveData { let archiveName: String let archiveDate: Date @Relationship(.cascade) var items: [Item] init(archiveName: String, archiveDate: Date, items: [Item]) { self.archiveName = archiveName self.archiveDate = archiveDate self.items = items } } Then, I'm adding the data to the context: let newArchive = ArchiveData(archiveName: name, archiveDate: Date.now, items: items) context.insert(newArchive) I can then display the archived data in a separate view. But when I restart the app, the items array of ArchiveData is empty. I couldn't find out, where I made a mistake. Can anyone help me?
1
0
373
Jun ’23