I am trying to split an Int into its individual digits, e.g. 3489 to 3 4 8 9, and then I want to put the digits in an Int array.
I have already tried putting the num
Swift 5
extension Int { func digits() -> [Int] { var digits: [Int] = [] var num = self digits.append(num % 10) while num >= 10 { num = num / 10 digits.append(num % 10) } return digits.reversed() } }