Format Strings with Templates in Swift

Gordon Fontenot published his StringTemplate library the other day. You can use it as a much better number formatter, for example:

  • “5125550001” is your user input
  • “(XXX) XXX-XXXX” is your template
  • “(512) 555-0001” is the result of applying the template

There are options to ignore overflow or crop the remainder when only inserting part of the required digits. I think that’s pretty slick!