I've got a simple premise I'm trying to implement, and I've created a test project to do so. Basically I want the app to load in a list, and then update the quantity of a given item in that list. I'm at a point where I get the following error message:
I've been over it and done as much research as I can, but now I'm stuck. Here is my code:
Where I store the array
Displaying the list (selecting an item here crashes app)
Details (what's supposed to show when selected)
Any advice or resources would be appreciated. I could be going about this completely wrong.
My first attempt was to use a local json and rewrite the file when saving a new value, but this came with it's own set of issues. My next attempt would be this: use Core Data to store a value that is attached to an index in an array.
Code Block "-[testies.QuantEntity quant]: unrecognized selector sent to instance 0x600000d68f00'
I've been over it and done as much research as I can, but now I'm stuck. Here is my code:
Where I store the array
Code Block import SwiftUI struct Consoles { var id: Int var name: String } final class ConsoleModel{ var consoles: [Consoles] = [ Consoles(id: 0, name: "NES"), Consoles(id: 1, name: "SNES"), Consoles(id: 2, name: "Genesis"), Consoles(id: 3, name: "N64") ] }
Displaying the list (selecting an item here crashes app)
Code Block import SwiftUI struct ConsoleList: View { var consoles = ConsoleModel().consoles var body: some View { NavigationView{ List(0 ..< consoles.count) {value in NavigationLink( destination: ConsoleDetails(consoles: QuantEntity()), label: { Text(consoles[value].name) }) } } } }
Details (what's supposed to show when selected)
Code Block import SwiftUI import CoreData struct ConsoleDetails: View { @State private var stepper: Int = 0 @Environment(\.managedObjectContext) var moc var consoles: QuantEntity var body: some View { Stepper("number of games = \(stepper)", value: $stepper){_ in let newQuant = QuantEntity(context: self.moc) newQuant.quant = Int32(self.stepper) try? self.moc.save() } .onAppear{ self.stepper = Int(consoles.quant) } } }
Any advice or resources would be appreciated. I could be going about this completely wrong.
My first attempt was to use a local json and rewrite the file when saving a new value, but this came with it's own set of issues. My next attempt would be this: use Core Data to store a value that is attached to an index in an array.