Validator
Rule based validation library for swift.
Features
- Rule based validation
- Class/Struct validation
- Validatable/Validator chaining
- Linux Compatible (Can be used with Kitura, Vapor, Perfect)
iPhone Screenshot
Installation
To install Validator, add it as a submodule to your project (on the top level project directory):
git submodule add https://github.com/smbhuin/Validator.git
Carthage
You can use Carthage. Specify in Cartfile:
github "smbhuin/Validator"
Run carthage
to build the framework and drag the built Validator.framework into your Xcode project. Follow build instructions.
CocoaPods
You can use CocoaPods.
platform :ios, '10.0'
use_frameworks!
target 'MyApp' do
pod 'AnyValidator'
end
or for newest version from specified branch of code:
pod 'AnyValidator', :git => "https://github.com/smbhuin/Validator", :branch => "master"
Swift Package Manager
You can use Swift Package Manager and specify dependency in Package.swift
by adding this:
dependencies: [
.package(url: "https://github.com/smbhuin/Validator.git", from: "1.0.5")
]
or more strict
dependencies: [
.package(url: "https://github.com/smbhuin/Validator.git", .exact("1.0.5"))
]
Usage
import Validator // If you are using Cocoapod then import AnyValidator
let v = Validator()
v.add(name: "Email", value: email, rules: [.required, .email])
v.add(name: "Name", value: name, rules: [.required, .fullName])
v.add(name: "Subject", value: subject, rules: [.required, .length(min: 10, max: 200)])
v.add(name: "Message", value: message, rules: [.required, .length(min: 10, max: 2000)])
let (valid, validatable, error) = v.validate()
API documentation
For more information visit our API reference.
License
This library is licensed under MIT. Full license text is available in LICENSE.