Post

Replies

Boosts

Views

Activity

SwiftData fatal error SwiftData.SwiftDataError._Error.loadIssueModelContainer)
Hello everyone, i'm working on an app to make my family life easier. it's was working fine with simple features but now I have added some feature but it's not working on the simulator or on my iPhone. The live preview is working fine... error message is Thread 1: Fatal error: Could not create ModelContainer: SwiftDataError(_error: SwiftData.SwiftDataError._Error.loadIssueModelContainer) nothing is very clear in the message except: Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={entity=Recette, attribute=isApero, reason=Validation error missing attribute values on mandatory destination attribute}}} issue looks to come from my variable "var isApero: Bool". Unfortunately I can't see the problem. below my model: import SwiftData @Model final class Recette { // @Attribute(.unique) var creationDate: Date var name: String var type: String var ingredient1: String var ingredient2: String var imageName: String var people1: Bool var people2: Bool var people3: Bool var people4: Bool var isEntree: Bool var isPlat: Bool var isDessert: Bool var isApero: Bool var isClassify:Bool init(name: String, type: String, ingredient1: String, ingredient2: String, imageName: String, people1: Bool = false, people2: Bool = false, people3: Bool = false, people4: Bool = false, isEntree: Bool = false, isPlat: Bool = false, isDessert: Bool = false, isApero1: Bool = false, isClassify:Bool = true) { self.creationDate = Date() self.name = name self.type = type self.ingredient1 = ingredient1 self.ingredient2 = ingredient2 self.imageName = imageName self.people1 = people1 self.people2 = people2 self.people3 = people3 self.people4 = people4 self.isEntree = isEntree self.isPlat = isPlat self.isDessert = isDessert self.isApero = isApero1 self.isClassify = isClassify } } here my detail view for items: import SwiftUI import SwiftData struct DetailRecette: View { @Bindable var recette: Recette var body: some View { VStack { TextField("nouvelle recette", text: $recette.name) .textFieldStyle(.roundedBorder) TextField("Ingredient1", text: $recette.ingredient1) .textFieldStyle(.roundedBorder) TextField("Ingredient2", text: $recette.ingredient2) .textFieldStyle(.roundedBorder) .padding(.bottom, 24.0) HStack { Text("people1") Toggle(recette.people1 ? "" : "", isOn: $recette.people1) } HStack { Text("people2") Toggle(recette.people2 ? "" : "", isOn: $recette.people2) } HStack { Text("People3") Toggle(recette.people3 ? "" : "", isOn: $recette.people3) } HStack { Text("People4") Toggle(recette.people4 ? "" : "", isOn: $recette.people4) } Divider() .padding(.bottom, 50) HStack { Text("Entrée") Toggle(recette.isEntree ? "" : "", isOn: $recette.isEntree) .padding(.trailing, 50) .onChange(of:recette.isEntree) { if recette.isEntree == true { recette.isPlat = false recette.isDessert = false recette.isClassify = false recette.isApero = false }} Text("Plat") Toggle(recette.isPlat ? "" : "", isOn: $recette.isPlat) .padding(.trailing, 50) .onChange(of:recette.isPlat) { if recette.isPlat == true { recette.isEntree = false recette.isDessert = false recette.isClassify = false recette.isApero = false }} } HStack { Text("Dessert") Toggle(recette.isDessert ? "" : "", isOn: $recette.isDessert) .padding(.trailing, 47) .onChange(of:recette.isDessert) { if recette.isDessert == true { recette.isEntree = false recette.isPlat = false recette.isClassify = false recette.isApero = false }} Text("Apéro") Toggle(recette.isApero ? "" : "", isOn: $recette.isApero) .padding(.trailing, 50) .onChange(of:recette.isApero) { if recette.isApero == true { recette.isEntree = false recette.isPlat = false recette.isDessert = false recette.isClassify = false } } } } Divider() HStack { Text("A classer") .padding(.leading, 120.0) // .frame(alignment: .trailing) Toggle(recette.isClassify ? "" : "", isOn: $recette.isClassify) .padding(.trailing, 140.0) .onChange(of:recette.isClassify) { if recette.isClassify == true { recette.isEntree = false recette.isPlat = false recette.isDessert = false recette.isApero = false }} } } } #Preview { DetailRecette(recette: Recette(name: "Recette", type: "Type", ingredient1: "ingredient1", ingredient2: "ingredient2", imageName: "image")) } Do you have any idea about whey this happens? Thank you for your help Julien.
1
1
759
Mar ’24
how to navigate to a list from a category
Hello Everyone, This is my first post as i'm a beginner in swifUI and in coding. I hope I will be clear enough. I'm working on a app that can allow me to find easily information about a factory. I have a list of factories where columns are mostly geographic information about the factory and numbers. I have sorted my list by categories where my variable is "state number - state name" in String. in each category I have a list of factory located in this state. I have a view (UsineRow) with selected detail from the factory, a view (UsineListe) displaying the list of all the factory's selected detail and another view with all details of the factory (reachable by clicking on one factory from the UsineListe view. Now I need a view where I will be able to display my categories and after that the list of factories inside my categories. For the moment, I have a view with all my categories and between directly the list of my factory selected details. ForEach(modelData.categories.keys.sorted(), id: \.self) { key in CategoryRow(categoryName: key, items: modelData.categories[key]!) that gives me: I have also an alternative view with only the list of my categories: obtained by: ForEach(modelData.categories.keys.sorted(), id: \.self) { key in Button(action: {}, label: { Text(key) }) This is the view I would prefer. BUT, I don't know how to make it clickable to the view of the list of selected details linked to the category only. I hope someone can help me and I hope to gave you clear information. Many thanks for your help. BR Julien
0
0
294
Feb ’24