The stepper should act on the model that is stored in memory.
Here you are inserting a new value, but it should increase the stepperValue in an entity of GroceryListItem.
First you need to create an entity, and save it.
let item = GroceryListItem()
context.insert(item)
Then you need to load that item, and use it in a binding to directly bind the stepper to its value.
This could become your list of elements:
List {
ForEach(items) { item in
@Bindable var bindingItem = item
NavigationLink {
// Destination view, a simple Stepper.
Stepper(value: $bindingItem.stepperValue) {
Text("\(item.stepperValue)")
}
} label: {
Text("Item with value: \(item.stepperValue)")
}
}
}
onChange is not needed for this. :)
Topic:
App & System Services
SubTopic:
iCloud & Data