Skip to main content
2 of 3
added 80 characters in body
mxcl
  • 27k
  • 12
  • 102
  • 100

Using Swift 5’s fancy new extendible interpolation:

extension DefaultStringInterpolation { mutating func appendInterpolation(pad value: Int, toWidth width: Int, using paddingCharacter: Character = "0") { appendInterpolation(String(format: "%\(paddingCharacter)\(width)d", value)) } } print("I ate \(pad: pieCount, toWidth: 3, using: "0") pies") // => `I ate 003 pies` 
mxcl
  • 27k
  • 12
  • 102
  • 100