ios – Binding a Stepper with a Dictionary SwiftUI


I am undecided if that is doable however I am presently attempting to create an inventory of steppers utilizing a dictionary[String: Int]. Utilizing the stepper I am hoping to alter the qty quantity within the dictionary. I attempted binding the worth to the stepper by first doing $primary[name] after which that did not work and so I ended up with $primary[keyPath: name] which resulted in fewer errors however nonetheless wasn’t working. To start with I used to be having issues of not wanting to alter the order of the dictionary that I made, and so I ended up with the ForEach beneath which labored for not altering the order of dictionary, nonetheless, I am questioning if that is one of many causes that the binding is not working.

    import SwiftUI
    struct AllSuppliesStruct {
        @State var primary = ["Regular Staples": 0, "Big Staples": 0]
        var physique: some View {
            Kind {
                //Fundamental Provides
                ForEach(primary.sorted(by: >), id: .key) { title, qty in
                    Stepper("(title), (qty)", worth: $primary[keyPath: name], in: 0...10)

If I pressed on the stepper solely as soon as for each Common and Massive Staples then I anticipate this within the dictionary

primary = ["Regular Staples": 1, "Big Staples": 1]


Leave a Reply

Your email address will not be published. Required fields are marked *