Is there a way to pass a ForEach variable out of the loop?

Here's my code.
        HStack {

            List {

                ForEach(friends, id:\.self) { row in

                    Button(action: { isDetail.toggle() }, label: {

                        Image(row.photo)

                            .resizable()

                            .aspectRatio(contentMode: ContentMode.fit)

                            .frame(width: 80, height: 80)

                            .clipped()

                            .clipShape(Circle())

                    })

                }

            }

        }

        .frame(height: 400)

        if isDetail {

            AccessibleMindsHalfModalView(isShown: $isDetail, modalHeight: 400, content: {

                Text("Hello")

            })

        }
Hi,
I'm not quite sure what you mean by "pass out of loop". The "row" variable is obviously only available inside the closure because it gets reused by the loop. But you can declare a
Code Block swift
@State var name: Bool = false (or any other type)

and modify that using a button inside the loop.

Take care,
David



Is there a way to pass a ForEach variable out of the loop?
 
 
Q