1

I need to check if the int is only one digit and if it is, I want to add a zero in front of it. I have this code but it doesnt work.

var minutes2 = Int(minutes)
var minutessize: Int = sizeofValue(minutes2)

if minutessize < 2 {
    var needStringHere = "0\(minutes2)"
    let a: Int? = needStringHere.toInt()
    minutes2 = a!
}
egor.zhdan
  • 4,555
  • 6
  • 39
  • 53
Deniz Yazar
  • 369
  • 2
  • 6
  • 12

1 Answers1

5

You can just check if the minutes count is less than 10:

var str = "\(minutes2)"
if (minutes2 < 10) { str = "0\(minutes2)" }
egor.zhdan
  • 4,555
  • 6
  • 39
  • 53