FormValidatorKit is a reusable Swift Package that provides a complete, scalable, and production-ready form validation framework for Apple platforms using SwiftUI.
It supports:
- Built-in validation support for TextField, SecureField, etc.
- Validation states: Idle, Focused, Valid, Invalid, Warning, Loading, Disabled
- Validation messages: Error, Success, Warning, Helper
- Built-in validators (Required, Email, Password, MinLength, etc.)
- Custom validation engine for async/API-based validation
- Reusable UI validation components (
ValidatedTextField,ValidatedSecureField) - Theming system for full UI customization
- Centralized
FormStatemanagement
- iOS 15+
- macOS 12+
- Swift 6.2+
In Xcode:
- Go to File > Add Packages...
- Enter your repository URL for
FormValidatorKit - Select the version/range and add the package
Or in Package.swift:
dependencies: [
.package(url: "https://github.com/Coderkube-App/FormValidatorKit.git", from: "1.0.0")
],
targets: [
.target(
name: "YourApp",
dependencies: [
.product(name: "FormValidatorKit", package: "FormValidatorKit")
]
)
]FormValidatorKit/
├── Sources/FormValidatorKit/
│ ├── Core/
│ ├── Data/
│ ├── Domain/
│ └── Presentation/
├── Tests/FormValidatorKitTests/
└── Package.swift
import SwiftUI
import FormValidatorKit
struct LoginView: View {
@State private var email = ""
var body: some View {
ValidatedTextField(
title: "Email",
text: $email,
validators: [.required(), .email()]
)
}
}struct SignupView: View {
@StateObject var form = FormState()
@State private var email = ""
@State private var password = ""
var body: some View {
Form {
ValidatedTextField(
title: "Email",
text: $email,
validators: [.required(), .email()],
formState: form,
fieldId: "email"
)
ValidatedSecureField(
title: "Password",
text: $password,
validators: [.required(), .minLength(8)],
formState: form,
fieldId: "password"
)
Button("Submit") {
if form.validateAll() {
print("Form is valid")
}
}
.disabled(!form.isValid)
}
}
}Run tests:
swift testThis repository uses a GitHub Actions workflow to automatically create version tags and GitHub Releases after changes are merged into main.
Version bump rules:
fix:or other non-breaking commits -> patch bump (x.y.Z)feat:-> minor bump (x.Y.0)BREAKING CHANGEin the commit body or footer -> major bump (X.0.0)
- Clean Architecture principles applied
- Reusable UI components
- Centralized form state validation
This project is licensed under the MIT License.