Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fromkk/valy
Valy is string validation library with Swift 4.
https://github.com/fromkk/valy
carthage cocoapods swift-4 swift4 validation validation-library valy
Last synced: about 5 hours ago
JSON representation
Valy is string validation library with Swift 4.
- Host: GitHub
- URL: https://github.com/fromkk/valy
- Owner: fromkk
- License: mit
- Created: 2016-11-15T07:17:46.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-18T22:18:13.000Z (about 5 years ago)
- Last Synced: 2024-09-24T20:40:39.233Z (about 10 hours ago)
- Topics: carthage, cocoapods, swift-4, swift4, validation, validation-library, valy
- Language: Swift
- Homepage:
- Size: 70.3 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Build Status](https://app.bitrise.io/app/dfcd9f87866e7757/status.svg?token=mN4n-Xqm61DJM76VTk3nlQ)](https://app.bitrise.io/app/dfcd9f87866e7757)# Valy
Valy is string validation library with Swift 5.
# Required
- Swift 5
- Xcode 10
- iOS 8~ / watchOS 2~ / tvOS 8~ / macOS 10.16~
- Carthage or CocoapodsIf you use Swift 4.2 or before, try [Valy 0.0.6](https://github.com/fromkk/Valy/releases/tag/0.0.6).
# Install
## with Carthage
Add `github "fromkk/Valy"` to **Cartfile** and execute `carthage update` command on your terminal in project directory.
Add **Carthage/Build/{Platform}/Valy.framework** to **Link Binary with Libralies** in you project.
If you doesn't use Carthage, add **New Run Script Phase** and input `/usr/local/bin/carthage copy-frameworks` in **Build Phases** tab.
Add `$(SRCROOT)/Carthage/Build/{Platform}/Valy.framework` to **Input Files**.## with Cocoapods
Add `pod 'Valy'` to **Podfile** and run `pod install` command on your terminal in project directory.
Open `{YourProject}.xcworkspace` file.# Usage
## Basic
```swift
import Valylet value: String? = nil
let result = Valy.factory(rules: [ValyRule.required]).run(with: value)
switch result {
case .failure(let rule):
switch rule {
case ValyRule.required:
print("value (\(value)) is required...")
default:
break
}
default:
print("value (\(value)) is successed!")
break
}
```## Add rule
```swift
Valy.factory().add(rule: ValyRule.required).add(rule: ValyRule.maxLength(10)).run(with: value)
```## Text Field
```swift
let textField = VLTextField(frame: frame)
textField.add(rules: [
ValyRule.required,
ValyRule.maxLength(30)
])
textField.ovserveValidation { (status, result) in
switch result {
case .success:
print("textField success")
case .failure(let rule):
print("failed \(rule)")
}
}
```## CustomRule
```swift
enum CustomValidatorRule: AnyValidatorRule {
case email
func run(with value: String?) -> Bool {
switch self {
case .email:
return doYourEmailValidation()
}
}
}Valy.factory().add(rule: CustomValidatorRule.email).run(with: value)
```