This page provides documentation for the InputKitSwift framework, a powerful library for handling user input in Swift applications. Whether you need to validate user input, format it, or customize the input controls, InputKitSwift has got you covered.
Table of Contents
Installation
To install InputKitSwift, you can use Swift Package Manager (SPM) or CocoaPods.
Swift Package Manager
To install using SPM, follow these steps:
- Open your project in Xcode
- Go to “File” > “Swift Packages” > “Add Package Dependency…”
- Enter the package repository URL: https://github.com/nimblehq/input-kit-swift
- Click “Next”
- Choose the package version rule (e.g., “Up to Next Major”)
- Click “Next”
- Confirm the package selection
- Click “Finish”
CocoaPods
To install using CocoaPods, include the following line in your Podfile:
pod 'InputKitSwift'
Run pod install
to install the framework.
Usage
Validating User Input
InputKitSwift provides various validators to help you validate user input. You can use these validators to ensure that the input meets specific requirements (e.g., it is not empty, it has a minimum length, it is a valid email address, etc.). To use the validator, import InputKit module in your Swift file:
import InputKitSwift
Then, use the desired validator as shown in the following example:
let validator = RegexValidator("^\\d{4}$", invalidMessage: "Invalid PIN code")
let isValid = validator.isValid("1234") // true
let errorMessage = validator.invalidMessage // "Invalid PIN code"
Formatting User Input
InputKitSwift also provides formatters that allow you to format user input according to specific formats (e.g., phone numbers, credit card numbers, etc.). To use a formatter, import InputKit module in your Swift file:
import InputKitSwift
Next, use the desired formatter as shown in the example below:
let formatter = PhoneNumberFormatter()
let formattedNumber = formatter.format("1234567890") // "123-456-7890"
Customizing Input Controls
InputKitSwift allows you to customize input controls easily. You can set custom styles, modify placeholder text, add icons, and more. Several control extensions are available to customize various input controls. For example, to customize a UITextField, you can do the following:
import InputKitSwift
Then, use the extension methods to customize the UITextField, as shown below:
let textField = UITextField()
textField.customize(placeholder: "Enter your email", font: UIFont.systemFont(ofSize: 16), textColor: .black, backgroundColor: .white)
textField.customizeClearButton(with: UIImage(systemName: "xmark.circle.fill"))
textField.addAccessoryView(texts: ["Done"], images: []) { selectedIndex in
// Handle accessory view button tap
}
Documentation
For a detailed documentation of all the available features and usage instructions, please refer to the official InputKitSwift repository on GitHub.
Examples
The InputKitSwift repository provides several examples demonstrating how to use the framework for various use cases. Please refer to the Examples directory on GitHub for these code samples.
Support
If you encounter any issues, have questions, or want to contribute, please feel free to reach out on the official InputKitSwift GitHub repository.
License
InputKitSwift is released under the MIT License. For more information, refer to the LICENSE file in the InputKitSwift repository.