Post

Replies

Boosts

Views

Activity

Reply to Swift Data value is duplicated between two variables in a class
The error turned out to be in the item file. I didn’t create the variable correctly in the initialization. I referenced the other variable, instead of the same variable. I found the easiest way to find the SwiftData Database is to search for defaul.store. I then found the right directory among the results. Did info on the fil, pulled the path as path. Then started terminal, then SQLite3, and opened the path and file name.
May ’24
Reply to Swift Data value is duplicated between two variables in a class
Basically, I'm creating a map, with each grid of the map a separate class and x and y variables within each class set to a unique combination. I want to be able to run each grid as a separate task, to run concurrently later. It should end up like [0,0],[0,1],[1,0],[1,1] for x and y. x and y do seem to update as showing in the print function, but when displayed, I get like [0,0],[1,1],[1,1],[0,0]. I cannot tell if it is being put in to storage, displayed, or both are the problem with duplicate grids being displayed. I wish I could go in and view the database directly, IE not using my code. I've tried creating a new project and c&p my code in to the same project, figuring maybe the database of the project is corrupt. Still the same problem. One though I have is to create a query to only display grids with x && y == 0. If it is stored wrong, then several grids should be displayed. If it is displayed wrong, then there should be only one grid displayed with this new query. Does anybody have further ideas of what can be the problem, troubleshoot it, and fix it? I have many more problems to create and fix to get my overall goal done.
Oct ’23
Reply to Inserting a Model entity with a relationship results in a runtime error.
I'm getting the same error. I am trying to do like a map thing, where a map, has many grid squares, which has many elevation points. If I delete a map, the map, all the grid squares and elevation points are deleted. If I delete a grid square, the grid square and all the elevation points are deleted. oddly it seems to be only the relationship between the last two classes that is the problem. hp_baseboard to be precise. I generally stick to microcontrollers for programming, so this is new. final class Route { //var timestamp: Date @Attribute(.unique) var route_name: String var route_season: String var route_processed: Bool var route_coordinates: String @Relationship(deleteRule: .cascade, inverse: \Baseboard.baseboard_route) var route_baseboards: [Baseboard] = [] //[UUID] init(route_name: String, route_season: String, route_processed: Bool, route_coordinates: String, route_baseboards: [Baseboard]) { //self.timestamp = timestamp self.route_name = route_name self.route_season = route_season self.route_processed = route_processed self.route_coordinates = route_coordinates self.route_baseboards = route_baseboards } } @Model final class Baseboard { //var baseboard_location: (Int, Int) //will have to decide which is which row/col var baseboard_column: Int var baseboard_row: Int var texture: [String] var baseboard_processed: Bool var baseboard_grid_size: Int var baseboard_route: Route? @Relationship(deleteRule: .cascade, inverse: \Height_Point.hp_baseboard) var baseboard_heightPoints: [Height_Point] = [] init(/*baseboard_location: (Int, Int)*/baseboard_column: Int, baseboard_row: Int, texture: [String], baseboard_processed: Bool, baseboard_grid_size: Int, baseboard_route: Route, baseboard_heightPoints: [Height_Point]) { //self.baseboard_location = baseboard_location self.baseboard_column = baseboard_column self.baseboard_row = baseboard_column self.texture = texture self.baseboard_processed = baseboard_processed self.baseboard_grid_size = baseboard_grid_size self.baseboard_route = baseboard_route self.baseboard_heightPoints = baseboard_heightPoints } } @Model final class Height_Point { var hp_baseboard: Baseboard? //var hp_location: (Int, Int) var hp_column: Int var hp_row: Int var hp_processed: Bool var hp_elevation: Float var hp_texture: String init(hp_baseboard: Baseboard, /*hp_location: (Int, Int),*/ hp_column: Int, hp_row: Int, hp_processed: Bool, hp_elevation: Float, hp_texture: String) { self.hp_baseboard = hp_baseboard //self.hp_location = hp_location self.hp_column = hp_column self.hp_row = hp_row self.hp_processed = hp_processed self.hp_elevation = hp_elevation self.hp_texture = hp_texture } } The problem is inserting the newItem3 withAnimation { let newItem = Route(route_name: "test route " + UUID().uuidString, route_season: "summer", route_processed: false, route_coordinates: "Somewhere", route_baseboards: [] ) modelContext.insert(newItem) let newItem2 = Baseboard(baseboard_column: 0, baseboard_row: 0, texture: ["Grid"], baseboard_processed: false, baseboard_grid_size: 10, baseboard_route: newItem, baseboard_heightPoints: [] ) /*modelContext.insert(newItem2) newItem2.baseboard_route?.route_baseboards.append(newItem2)*/ let newItem3 = Height_Point( hp_baseboard: newItem2, hp_column: 0, hp_row: 0, hp_processed: false, hp_elevation: 0, hp_texture: "Grid" ) modelContext.insert(newItem3) /*newItem3.hp_baseboard? .baseboard_heightPoints.append(newItem3)*/ } } if I don't put something in for baseboard_Route or hp_Baseboard, then it throws up another problem. Yet I'm not sure this is correct either.
Aug ’23