A Swift framework for formatting text input on iOS, macOS and tvOS.
While developing an application, you may encounter a task to format text input of bank card information, phone numbers, etc. TextInputKit strives to help you solve this task efficiently.
TextInputKit is a framework with:
- consistent Swift API on iOS, macOS and tvOS;
- built-in formats:
- capability to add custom formats;
- total code coverage.
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthageTo integrate TextInputKit into your Xcode project using Carthage, specify it in your Cartfile:
github "artyom-stv/TextInputKit"
Run carthage update to build the framework and drag the built TextInputKit.framework into your Xcode project.
First, a TextInputFormat is created (see how to create a built-in format or a custom format).
letformat=TextInputFormats.bankCardNumber() // -> `TextInputFormat<BankCardNumber>`To drive text input formatting, a TextInputBinding is created.
lettextInputBinding= format.bind(to: textField) // -> `TextInputBinding<BankCardNumber>`If you don't need to reuse a format, the code can be shortened to the following:
lettextInputBinding=TextInputFormats.bankCardNumber().bind(to: textField) // -> `TextInputBinding<BankCardNumber>`textInputBinding performs the following functions:
- formats text input in
textFieldaccording toformat(in this case, according to the bank card number format); - updates
textInputBinding.valuewhen text intextFieldchanges; - notifies of the events.
The functions mentioned above are performed only while textInputBinding is bound to textField:
textFieldis alive;textInputBindingis alive;textInputBinding.unbind()isn't called.
textInputBinding.eventHandler ={[unowned self] event inswitch event {caselet.editingChanged(state, changes):if changes.contains(.value){
// Use `state.value`
}default:break}}- iOS 8.0+ / macOS 10.10+ / tvOS 9.0+
- Xcode 8.0+
- Swift 3.0+
There are plans to extend the set of built-in formats.
Please, create an issue or comment an existing issue, if you need support of a new format.
Examples of feasible formats:
- Pattern-based Format;
- Decimal Number;
- E-mail.
TextInputKit is released under the MIT license. See LICENSE for details.