So, you will pass the array populated with the prices (in fact, you probably need to pass more information, to know to which pizza or customer a price refers to).
Is it for SwiftUI or UIKit ?
for SwiftUI, you would have a State var with the costs (or more info) and could use List to display
@State var costs: [Double] = [] // You will have to append this array when you add a pizza
In the body of the View, something like:
struct ContentView: View {
@State var costs: [Double] = [] // You will have to append this array when you add a pizza
@State var newCost: Double = 0
var body: some View {
VStack {
List(costs, id: \.self) { cost in
Text("cost: \(String(format: "%4.2f", cost) )")
}
HStack {
Text("New pizza cost")
TextField("", value: $newCost, format: .number)
.border(.blue)
}
Button(action: {
if newCost > 0 { self.costs.append(newCost) }
newCost = 0
}) {
Text("Append")
}
Spacer()
}
}
}