To format a phone number in Swift, we can create an extension for UITextField that will handle the formatting. Here is an example of how we can format a US phone number (10 digits) with dashes:
main.swift740 chars19 lines
To use this extension, you can simply call textField.formatPhoneNumber()
on any UITextField
that you want to format the phone number for.
gistlibby LogSnag