Looking for opinions - Math Tables in a List

Hi,
I am looking for opinions on the best way to handle a problem I'm having.

My client wants his app to show a list of math tables, such as 1+1 = 2, 2+2 = 4, and so on. I have a list view with said tables in an array, which I manually have to input in. He wants the list to go from 1 to 20.

I'd assume that I would need some sort of for....next loop, but how would I show that in a list?

Thanks for any help you can give.

This is what I have so far:

Code Block
import SwiftUI
import UIKit
struct ATables: View {
  
  var tables = ["Temporary","1 + 1 = 2","2 + 2 = 4"]
  
    var body: some View {
        
      NavigationView {
   
          List {
        
        ForEach(self.tables, id: \.self) { show in
          
          HStack {
          Image(systemName: "arrow.right")
            .resizable()
            .frame(width: 30, height: 20, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
          Text(show)
            .font(.custom("Chalkboard", size: 50))
          }
        }
      }.navigationBarTitle(Text("Addition Tables (1 - 20)"))
          .navigationBarTitleDisplayMode(.inline)
    }
}
struct ATables_Previews: PreviewProvider {
    static var previews: some View {
        ATables()
    }
}
}


Are you asking how to generate the list dynamically? Here is one way below. You can't have a for loop directly in the body of a SwiftUI view. Maybe in the future, but for now you have to use the ForEach thing.

Code Block
func makeTables() -> [String] {
    var result = ["Temporary"]
    for i in 1...20 {
        result.append("\(i) + \(i) = \(i+i)")
    }
    return result
}
struct ContentView: View {
    var tables: [String] = makeTables()
    var body: some View {
        NavigationView {
            List {
                ForEach(self.tables, id: \.self) { show in
                    HStack {
                        Image(systemName: "arrow.right")
                            .resizable()
                            .frame(width: 30, height: 20, alignment: .center)
                        Text(show)
                            .font(.custom("Chalkboard", size: 50))
                    }
                }
            }.navigationBarTitle(Text("Addition Tables (1 - 20)"))
            .navigationBarTitleDisplayMode(.inline)
        }
    }
}

Thank you. Anyone else?
Looking for opinions - Math Tables in a List
 
 
Q