0

I have a ForEach inside a picker with numbers from 0 to 20 that shows 0, 1, 2...20 but instead I need to display 00, 01, 02...20. How can I do it?

xmetal
  • 681
  • 6
  • 16

1 Answers1

3

You use the normal string formatting String(format: "%02d", 5):

@State var num: Int = 0

var body: some View {
   Picker("", selection: $num) {
      ForEach(0..<21) { v in 
         Text(String(format: "%02d", v)) 
      }
   }
}
New Dev
  • 48,427
  • 12
  • 87
  • 129