All Projects → heitorgcosta → Quiver

heitorgcosta / Quiver

Licence: mit
Validation, searching and filtering made easy for swift.

Programming Languages

swift
15916 projects
swift4
162 projects

Projects that are alternatives of or similar to Quiver

Bfkit
BFKit is a collection of useful classes and categories to develop Apps faster.
Stars: ✭ 811 (+2903.7%)
Mutual labels:  xcode, cocoapods, carthage
Tbuiautotest
Generating UI test label automatically for iOS.
Stars: ✭ 333 (+1133.33%)
Mutual labels:  xcode, cocoapods, carthage
Stevia
🍃 Concise Autolayout code
Stars: ✭ 3,182 (+11685.19%)
Mutual labels:  xcode, cocoapods, carthage
Imageloaderswift
A lightweight and fast image loader for iOS written in Swift.
Stars: ✭ 290 (+974.07%)
Mutual labels:  xcode, cocoapods, carthage
Uitextfield Navigation
🏄‍♂️ UITextField-Navigation makes it easier to navigate between UITextFields and UITextViews
Stars: ✭ 436 (+1514.81%)
Mutual labels:  xcode, cocoapods, carthage
Netfox
A lightweight, one line setup, iOS / OSX network debugging library! 🦊
Stars: ✭ 3,188 (+11707.41%)
Mutual labels:  xcode, cocoapods, carthage
Maplebacon
🍁🥓 Lightweight and fast Swift library for image downloading, caching and transformations
Stars: ✭ 322 (+1092.59%)
Mutual labels:  xcode, cocoapods, carthage
Localize
Localize is a framework writed in swift to localize your projects easier improves i18n, including storyboards and strings.
Stars: ✭ 253 (+837.04%)
Mutual labels:  xcode, cocoapods, carthage
Gradientcircularprogress
Customizable progress indicator library in Swift
Stars: ✭ 407 (+1407.41%)
Mutual labels:  xcode, cocoapods, carthage
Stepslider
StepSlider its custom implementation of slider such as UISlider for preset integer values.
Stars: ✭ 391 (+1348.15%)
Mutual labels:  xcode, cocoapods, carthage
Audioindicatorbars
AIB indicates for your app users which audio is playing. Just like the Podcasts app.
Stars: ✭ 279 (+933.33%)
Mutual labels:  xcode, cocoapods, carthage
Sidemenu
Simple side/slide menu control for iOS, no code necessary! Lots of customization. Add it to your project in 5 minutes or less.
Stars: ✭ 5,267 (+19407.41%)
Mutual labels:  xcode, cocoapods, carthage
Xcode One Dark
Atom One Dark theme for Xcode
Stars: ✭ 273 (+911.11%)
Mutual labels:  xcode, cocoapods, carthage
Anyformatkit
Simple text formatting in Swift
Stars: ✭ 296 (+996.3%)
Mutual labels:  xcode, cocoapods, carthage
Colorizeswift
Terminal string styling for Swift.
Stars: ✭ 253 (+837.04%)
Mutual labels:  xcode, cocoapods, carthage
Microfeatures Guidelines
📦📝 uFeatures guidelines
Stars: ✭ 315 (+1066.67%)
Mutual labels:  xcode, cocoapods, carthage
Irldocumentscanner
A drop-in Objective-C ViewController that will Automatically scan a document for you you.
Stars: ✭ 172 (+537.04%)
Mutual labels:  xcode, cocoapods, carthage
Shsearchbar
The search bar that doesn't suck.
Stars: ✭ 206 (+662.96%)
Mutual labels:  xcode, cocoapods, carthage
Restofire
Restofire is a protocol oriented networking client for Alamofire
Stars: ✭ 377 (+1296.3%)
Mutual labels:  xcode, cocoapods, carthage
Swiftinstagram
Instagram API client written in Swift
Stars: ✭ 570 (+2011.11%)
Mutual labels:  xcode, cocoapods, carthage

Quiver

license Swift 5 Xcode 10.2 CocoaPods Compatible Carthage compatible Build Status codecov codebeat badge

Quiver is a library that provides an easy way to validate, search and filter objects.

Installation

Cocoapods

pod 'Quiver', '~> 1.2'

Carthage

github "heitorgcosta/Quiver" ~> 1.2  

Usage

Validating

Objects can be easily validated by implementing the Validatable protocol. To do so, validations(with:) must be implemented. The mapping is made with the new Swift 4 smart keypaths.

struct Person {
    var name: String?
    var age: Int?
}

extension Person: Validatable {
    func validations(with mapper: ValidatorMapper) {
        // Name is required and must be at least 4 characters long.
        mapper[\Person.name] = [.required(),
                                .length(min: 4)]

        // Age is required and must be 18 or over
        mapper[\Person.age] = [.required(),
                               .greaterOrEqual(to: 18)]
    }
}

Any object implementing Validatable can call validate(), which returns a result object.

let person = Person(name: "Hector", age: 23)
let result = person.validate()

print(result.success) // Prints 'true'

The results also contains the errors occurred.

let person = Person(name: "Hector", age: nil) 
let result = person.validate()

print(result.success) // Prints 'false'
print(result.error.items.count) // Prints 1, since it does not fulfill the 'required' validation

Also, each validator can contain a custom message defined by you.

extension Person: Validatable {
    func validations(with mapper: ValidatorMapper) {
        mapper[\Person.name] = [.required(message: "The name is required"),
                                .length(min: 4, message: "The name should be at least 4 characters long")]

        mapper[\Person.age] = [.required(message: "The age is required"),
                               .greaterOrEqual(to: 18, message: "The age should be 18 or over")]
    }
}

let person = Person(name: "Heitor", age: 17)
let result = person.validate()

print(result.error.firstItem?.message ?? "No errors found") // Will print 'The age should be 18 or over'

Validators are still in the beginning and more will be added in the future.

Searching

First, objects to be searched must implement the Searchable protocol. The searchableFields() function should return all searchable properties.

struct Person {
    var name: String
    var age: Int
}

extension Person: Searchable {
    func searchableFields() -> [Any?] {
        return [name, age]
    }
}

Then, any array of this object can use the search() function to get an array with the matching results.

// If any searchable field of a person contains "John", it is returned in the result array.

let results = personsArray.search(with: "John") // Search is not case sensitive by default.
let caseSensitiveResults = personsArray.search(with: "John", caseSensitive: true) // Explicit case sensitivity

Filtering

An array of objects can be filtered using the validators included in this library using the filter(by:with:), using a keypath and an array of validators.

let persons: [Person] = [] // Just imagine a great collection of persons
let filtered = persons.filter(by: \Person.name, with: [.length(min: 4)]) // Filter persons that contains name with length of at least 4 characters

License

Quiver is released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].