Swiftpack.co -  Package - luximetr/AnyFormatKit
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Simple text formatting in Swift
.package(url: "https://github.com/luximetr/AnyFormatKit.git", from: "2.5.0")

AnyFormatKit: Simple text formatting in Swift

CI Status Pod Version License Platform SwiftPM compatible Swift

Text formatting framework written on Swift 5.0.


:performing_arts: Convert string into formatted string and vice versa
:bicyclist: Formatting text during typing
:hash: Set format using '#' characters like '### ##-###'
:stuck_out_tongue: Supporting emojis
:heavy_dollar_sign: Formatting money amount
:parking: Formatting with placeholders
:seedling: UITextField and UITextView support


To run the example project, clone the repo and run pod install from the Example directory first.


Phone number example

Currency example

Card number example

Placeholder number number example


  • iOS 8.0+
  • Swift 4.0+
  • Xcode 9.0+


AnyFormatKit has SwiftUI version, that exists as separate framework AnyFormatKitSwiftUI

Migration Guides



AnyFormatKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'AnyFormatKit', '~> 2.5.0'

Then, run the following command:

$ pod install

Swift Package Manager

AnyFormatKit is available with Swift Package Manager. Once you have your Swift package set up, than simply add AnyFormatKit to the dependencies value of your Package.swift

dependencies: [
    .package(url: "https://github.com/luximetr/AnyFormatKit.git", .upToNextMajor(from: "2.5.0"))



import AnyFormatKit

Formatting with TextFormatter

let phoneFormatter = DefaultTextInputFormatter(textPattern: "### (###) ###-##-##")
let phoneInputController = TextFieldInputController()

textField.delegate = phoneInputController
phoneInputController.formatter = phoneFormatter

Get only your input

phoneNumberFormatter.unformat("+51 (013) 442-55-11") // +51013442551 

In case you want to use textField.delegate by yourself

let phoneFormatter = DefaultTextInputFormatter(textPattern: "### (###) ###-##-##")

// inside of UITextFieldDelegate shouldChangeTextIn method
let result = formatter.formatInput(currentText: textField.text ?? "", range: range, replacementString: string)
textField.text = result.formattedText

You can find example of setCursorLocation here

Formatter kinds


luximetr, luximetr.notification@gmail.com

Say thank you


AnyFormatKit is available under the MIT license. See the LICENSE file for more info.


Stars: 299
Last commit: 3 weeks ago

Release Notes

Allow backspacing group character and send editing events
1 year ago
  • Allow grouping character to be backspaces by moving the cursor one index to the left when the user attempt to backspace this character
  • Fix issue where the text input change would not be sent when the .content property of TextInput changes

Solves: https://github.com/luximetr/AnyFormatKit/issues/8

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco