I begin testing my IOS swiftdats Xcode 15 swift 5 on Sonoma and I am able to create my siwftdata tables as well as add records to several of the tables, Then as I proceeded with my te tables disappear and I get this error in the Xcode debug console: error: Error: Persistent History (6) has to be truncated due to the following entities being removed: ( AppSettings, Invoice, Clientele, Pay, InvoiceItem, TrackingArt ) This app used to work fine and as I was making changes it started behaving in this manner. Beside the code I will supply the entire debug console with the attached file
Here is how I have the swift data containers setup.
import SwiftData
import TipKit
import CloudKit
@main
struct ArtManagerApp: App {
@StateObject private var copyInvoiceDetails = CopyInvoiceDetails()
@StateObject private var copyPaymentDetails = CopyPaymentDetails()
@StateObject private var artTypeSettings = ArtTypeSettings()
@StateObject private var tipManager = TipManager()
// @Query(sort: \ArtPiece.artPieceID, order: .forward) private var artPieces: [ArtPiece]
// @Query(sort: \AppSettings.setID, order: .reverse) private var settingsList: [AppSettings]
var sharedModelContainer: ModelContainer = {
let schema = Schema([
ArtPiece.self, Clientele.self, TrackingArt.self, Invoice.self, InvoiceItem.self, AppSettings.self, Pay.self
])
let modelConfiguration = ModelConfiguration(schema: schema,
isStoredInMemoryOnly: false)
do {
return try ModelContainer(for: schema, configurations: [modelConfiguration])
} catch {
fatalError("Could not create ModelContainer: \(error)")
}
}()
var body: some Scene {
WindowGroup {
ContentView()
.navigationTitle("🎨 Art Manager")
.environmentObject(artTypeSettings)
.environmentObject(copyInvoiceDetails)
.environmentObject(copyPaymentDetails)
.environmentObject(tipManager) // Pass it to the ContentView
.modelContainer(sharedModelContainer)
}
}
}
class TipManager: ObservableObject {
@Published var tips: [ArtManagerTip] = []
init() {
loadTips()
}
func loadTips() {
tips = [ArtManagerTips.search_tip, ArtManagerTips.delete_tip, ArtManagerTips.extendedSearch_tip,
ArtManagerTips.searchPayments_tip, ArtManagerTips.searchArt_tip, ArtManagerTips.librarySearch_tip, ArtManagerTips.artMaintenanceSearch_tip]
}
}
class CopyPaymentDetails: ObservableObject {
@Published var payNumber: Int32 = 0
@Published var payType: String = ""
@Published var payPatronID: Int32 = 0
@Published var payPatronName: String = ""
@Published var payPatronAddress: String = ""
@Published var payPaymentAmount: Double = 0.0
@Published var payDatePayed: Date = Date()
}
class CopyInvoiceDetails: ObservableObject {
@Published var invoiceNumber: Int32 = 0
@Published var invoicePatronName: String = ""
@Published var invoicePatronPO: String = ""
@Published var invoiceDateCreated: Date = Date()
@Published var artPieceIDSaved: [Int32] = []
}
Xcode debug console: error: Error: Persistent History (6) has to be truncated due to the following entities being removed: ( AppSettings, Invoice, Clientele, Pay, InvoiceItem, TrackingArt )
This error indicates that you removed some models in the current version schema without doing migration. I discussed this topic in the other post. You can take a look if that helps.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.