Array Elements - Getting Control

Starting with a code example :

struct SomeListView: View {
@Binding var data: Data
  var body: some View {
    List{
      Section{
//Here's the rub, to take advantage of onDelete I'm using this method
        ForEach(data.arr[0], id: \.self) { item in
// which works great for display
          Text(item[2])  
// but because item is an array
          TextField("FieldName", text: item[0])
// calls an error ... you probably guessed it. Right. Cannot convert String to Binding String kinda thing ... to add a pickle to the picnic, another string within that array I want to bind to gets passed to a string to bool value function that requires the binding

//The question is pretty basic ... how to aquire the index number of the desired string so I can do something like this
        ForEach(data.array[0], id: \.self) { item in
//aquire index num or loop count to use as index ????
          TextField("FieldName", text: $data.arr[0][index][0])
          TextField("FieldName", text: $data.arr[0][index][1])
          CheckBoxFromString(isSetString: $data.arr[0][index][2])

      }
      .onDelete { indices in
        data.arr[0].remove(atOffsets: indices)
      }
    }
  }
}

Apologies for vagueness and ambiguity or if this just seems blindingly obvious. I'm fairly fresh to Swift, SwiftUI etc ... it's a learning curve. Appreciate any tips Cheers

Can you clarify what you want to ask?

Here is some code to show how to do:

    @State var someItems: [[String]] = [["Hello", "You", "Boys", "Girls"], ["Hello2", "You2", "Boys2", "Girls2"], ["Hello3", "You3", "Boys3", "Girls3"]]

  var body: some View {
    
      VStack {
          ForEach(someItems, id: \.self) { item in
            Text(item[2])
            TextField("FieldName", text: $someItems[0][0])
            TextField("FieldName", text: $someItems[0][1])
          }

I want to use the method 'ForEach(data.arr[0], id: \.self { item in' to take advantage of the .onDelete { indices in method Im pretty sure onDelete is refering to indices that were communicated by the ForEach method using another ForEach method ie ForEach(data.arr[0] { i in is great in terms of identifying the indexes, except it breaks the onDelete method So I was thinking I could just throw a counter in to the forEach method, because I'm still becoming familiar with Swifts architecture to be honest I have no Idea how to simply apply that concept. private var index: Int = 0 ForEach(data.array[0], id: \.self) { item in index += 1 TextField("FieldName", text: $data.arr[0][index][0]) CheckBoxFromString(isSetString: $data.arr[0][index][2]) but it seems it's not approachable in this way because it creates a conflict for the 'View' class i need to correctly identify the index so I can apply binding to it $data.arr[0][index][0] The following methods require binding in order to operate a) TextField() b) CheckBoxFromString()

Is that a bit clearer?

p.s This is my first post .... I'm also learning about the forum post formatting

Unfortunately, the forums lack very important feature -- editing old posts. You may need to use Your Answer to show additional info. In addition, please show the complete definition of your Data. (Generally, you should better not use the same type name as very popular standard type names.)

Without reiterating, let's assume that data is a generic name I used to represent the conceptual approach I was taking. Unfortunately, as you say I can't edit the post, and where I refered to the ForEach method I incorrectly typed 'array' which should of been 'arr', once again conceptual representation. Ultimately the question in it's simplest form is: Can I increment a value with each loop of the ForEach method? If so, How?

something like ( index += 1 ) would really be what I'm looking for

If you say you would not like to show additional info using Your Answer, it is your choice. Hope you can solve your issue soon.

Thanks for your constructive input. Now don't you worry about my issue ok. I'm sure things will work out fine. A solution will present itself oneway or another. p.s - data was used in this context : "@Binding var data: DataModel" - an 'Identifiable data struct' ..

@azabug, I just would like to worry about the problems with enough info provided in a readable manner.

Then, you should have something like:

@State var someItems: [[[String]]] = arr[[["stringy", "stringy", "stringybool"], ["stringy", "stringy", "stringybool"]], [["stringy", "stringy", "stringybool"], ["stringy", "stringy", "stringybool"]], [["stringy", "stringy", "stringybool"], ["stringy", "stringy", "stringybool"]]] 

An item is [[String]] [["stringy", "stringy", "stringybool"], ["stringy", "stringy", "stringybool"]]

  var body: some View {
    
      VStack {
          ForEach(someItems, id: \.self) { item in
            Text(item[2])
            TextField("FieldName", text: $someItems[0][0][0])
            TextField("FieldName", text: $someItems[0][1][2])
          }
Array Elements - Getting Control
 
 
Q