简体   繁体   中英

Unsafe Pointer?

I am receiving this error message.

I am trying to make a subview that I can reuses to display a row in my app.

For some reason, it is pointing to the index variable that I am using to iterate over my enum in my List to display my data.

Why is this happening? I am not sure how to refer to this variable outside of the subview.

 struct DisplayRow: View {
    
    var name: String
    var code: String
    var value: Double
    var counter: Int
    
    var body: some View {
        
        List(0..<counter, id: \.self) {index in
            
            VStack {
                HStack {
                    Text(name)

                    Text(code)
                }
                Text("$\(value)")
            }
        }
        
    }
}

struct ContentView: View {
    
    var body: some View {
        List {
            Section(header: Text("Wounds")) {
                DisplayWoundRow()
            }
            Section(header: Text("Debride")) {
                DisplayRow(name: debride.allCases[index].rawValue, code: debridecode.allCases[index].rawValue, value: debridevalue.allCases[index].rawValue, counter: debride.allCases.count)
            }
        }

截屏

You need ForEach for that, like

Section(header: Text("Debride")) {
  ForEach(0..<debride.allCases.count, id: \.self) { index in          // << here !!
    DisplayRow(name: debride.allCases[index].rawValue, code: debridecode.allCases[index].rawValue, value: debridevalue.allCases[index].rawValue, counter: debride.allCases.count)
  }
}

*I don't have all those types and cannot test, so typos or other errors are on you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM