ForEach with 2 arrays String how ?

Hi there I was wandering how to pass 2 String Arrays in ForEach loops the first one is Image(systemName: String), the second is name for that image. by example a button in a VStack with the image on top , under the Text(name). Thank for your help

Answered by Claude31 in 745393022

Welcome to the forum. It would help if you showed your tentative code, not paraphrase it.

But, if I understand your question, you should use an array of a struct:

struct ImageModel: Identifiable {
    let id = UUID()
    var systemName: String
    var realname: String
}

Then you have an array:

    @State var images: [ImageModel] = [] // Populate it

Use it in ForEach:

     ForEach($images) { $image in }
Accepted Answer

Welcome to the forum. It would help if you showed your tentative code, not paraphrase it.

But, if I understand your question, you should use an array of a struct:

struct ImageModel: Identifiable {
    let id = UUID()
    var systemName: String
    var realname: String
}

Then you have an array:

    @State var images: [ImageModel] = [] // Populate it

Use it in ForEach:

     ForEach($images) { $image in }
ForEach with 2 arrays String how ?
 
 
Q