TFManager
Let's say you have multiple UITextFields to get data from users. You need to handle each field keyboard's return key and add an accessory view to the keyboard for navigating through fields. TFManager will do this for you in just one line of code! And if you want more you can add validation rules to the text fields and check if they're valid or not.
Navigate
Installation
Ready for use on iOS and iPadOS 11+.
Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
Once you have your Swift package set up, adding as a dependency is as easy as adding it to the dependencies value of your Package.swift.
dependencies: [
.package(url: "https://github.com/abspr/TFManager", .upToNextMajor(from: "1.1.0"))
]
CocoaPods:
CocoaPods is a dependency manager. For usage and installation instructions, visit their website. To integrate using CocoaPods, specify it in your Podfile:
pod 'TFManager'
Manually
If you prefer not to use any of dependency managers, you can integrate manually. Put Sources/TFManager folder in your Xcode project. Make sure to enable Copy items if needed and Create groups.
Basic Usage
- Create an instance of TFManager in your
viewController
var fieldsManager = TFManager()
- Add your
textFieldsto it:
fieldsManager.add([nameField, mailField, ageField])
- There is no more steps
😯
Validate All Fields
You can add rules to your UITextFields and ask TFManager to apply validation to all of child fields:
- Change your textField class to
ValidatableField.
- Then you can call
validate()method on yourTFManagerinstance.
let result = fieldsManager.validate()
result.forEach { (invalidField, validationResult) in
invalidField.textColor = .systemRed
print(validationResult.message)
}
TFManager's delegate and use its methods to get notified which textField is become active or its text is changing:
fieldsManager.delegate = self
extension ViewController: TFManagerDelegate {
func textDidChange(_ textField: UITextField, validationResult: ValidationResult?) {
guard let validationResult = validationResult else { return }
textField.textColor = validationResult.isValid ? .label : .systemRed
}
}
ValidatableField and customize your textField. Override didFailValidation(_:) and didPass() methods to handle valid/invalid states (eg: show/hide the error label)
Rules
TFManager comes with set of rules (TextRulesSet) and you can add them to any ValidatableField:
ageField.rulesRepo.add(TextRulesSet.numbersOnly())
ageField.rulesRepo.add(TextRulesSet.minLenght(1))
ageField.rulesRepo.add(TextRulesSet.maxLenght(2))
struct and implement TextRule:
struct YourRule: TextRule {
var message: String
func validate(_ text: String) -> Bool {
// code
}
}
Contact
email : [email protected]
License
TFManager is available under the MIT license. See the LICENSE file for more info.

