Giter Site home page Giter Site logo

honour's Introduction

Honour

Language License Version

Validation library for iOS inspired by Respect/Validation.

Validator.mustBe(Uppercase()).andMust(StartsWith("F")).validate("FOOBAR")

โ— If you want to use this library in Objective-C classes, check HonourBridge repo.

Usage

Single Validation

let username = "jeanpimentel"
Lowercase().validate(username) // true

Chained Validation

It is possible to use validators in a chain.

let v = Validator.addRule(Lowercase()).addRule(NoWhitespace()).addRule(Length(min: 3, max: 60))
v.validate("jeanpimentel") // true

Syntax sugar

It is possible to use some syntax tricks to be highly expressive.

let v = Validator.mustHave(Length(min: 3, max: 60)).and(NoWhitespace()).andMustBe(Lowercase())
v.validate("jeanpimentel") // true

Granularity control

We have 3 validation methods

  • validate() - returns true or false
  • assert() - returns a tuple with true/false and all errors, if any.
  • check() - returns a tuple with true/false and the first error, if any.

Validate

func validate(value: AnyObject) -> Bool
let validator = Validator().addRule(Uppercase()).addRule(StartsWith("J"))
validator.validate("JEAN") // true
validator.validate("PIMENTEL") // false

Assert

func assert(value: AnyObject) -> (isValid: Bool, invalidRules: Array<Rule>)
let validator = Validator().addRule(Uppercase()).addRule(StartsWith("J"))

let result = validator.assert("JEAN")
result.isValid      // true
result.invalidRules // [] (empty)

let result = validator.assert("Jean")
result.isValid      // false
result.invalidRules // [Uppercase()]

let result = validator.assert("Felipe")
result.isValid      // false
result.invalidRules // [Uppercase(), StartsWith("J")]

Check

func check(value: AnyObject) -> (isValid: Bool, invalidRule: Rule?)
let validator = Validator().addRule(Uppercase()).addRule(StartsWith("J"))

let result = validator.check("JEAN")
result.isValid     // true
result.invalidRule // nil

let result = validator.check("Felipe")
result.isValid     // false
result.invalidRule // Uppercase()

let result = validator.check("FELIPE")
result.isValid     // false
result.invalidRule // StartsWith("J")

Installation

Package is available on CocoaPods. See the "Using CocoaPods" guide for more information.

use_frameworks!
platform :ios, '7.0'
pod 'Honour', '~> 1.1.1'

Requirements

Honour Version Minimum iOS Target Notes
1.1.1 iOS 7 Swift 1.2 (Xcode 6.3) is required.

Contributing

  • If you found a bug, and can provide steps to reliably reproduce it, open an issue.

  • If you have a feature request, open an issue.

  • If you want to contribute, submit a pull request.

    1. Fork it!
    2. Create your feature branch: git checkout -b my-new-feature
    3. Commit your changes: git commit -am 'Add some feature'
    4. Push to the branch: git push origin my-new-feature
    5. Submit a pull request

Validators

Always a working in progress...

Available now:

Localized validators

  • Brazil (BR)

License

Honour is released under the MIT license. See LICENSE for details.

honour's People

Contributors

filhodanuvem avatar jeanpimentel avatar jpimentel-ciandt avatar readmecritic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

honour's Issues

Crash with iOS9

Hey, thanks for the great library!
It worked like a charm until today when I updated to iOS 9. My app is crashing with the following log output:

dyld: Library not loaded: @rpath/Honour.framework/Honour
  Referenced from: /private/var/mobile/Containers/Bundle/Application/6834122C-6D06-464B-B2C4-375E8890F3C0/highfive.app/highfive
  Reason: no suitable image found.  Did find:
    /private/var/mobile/Containers/Bundle/Application/6834122C-6D06-464B-B2C4-375E8890F3C0/highfive.app/Frameworks/Honour.framework/Honour: mach-o, but wrong architecture
    /private/var/mobile/Containers/Bundle/Application/6834122C-6D06-464B-B2C4-375E8890F3C0/highfive.app/Frameworks/Honour.framework/Honour: mach-o, but wrong architecture
    /private/var/mobile/Containers/Bundle/Application/6834122C-6D06-464B-B2C4-375E8890F3C0/highfive.app/Frameworks/Honour.framework/Honour: mach-o, but wrong architecture

I tried removing the app and rebuilding, but nothing seems to help.

Any ideas? Thanks.

Add Carthage support

I would be nice to have Carthage support. You only need to create a project with a shared scheme that has a framework target.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.