Is it possible to get all digits of the Int
variable in the Swift not converting this variable to the string
?
Small example how i am doing this now:
let number = 123456
let array = String(number).characters.map{Int(String($0)) ?? 0}
Is it possible to get all digits of the Int
variable in the Swift not converting this variable to the string
?
Small example how i am doing this now:
let number = 123456
let array = String(number).characters.map{Int(String($0)) ?? 0}
Something like this?
var number = 123456
var array = [Int]()
while number > 0 {
array.append(number % 10)
number = number / 10
}
array.reverse()