Latest 0.2.0
Homepage https://github.com/naoty/AnyQuery
License MIT
Platforms ios 8.0, requires ARC
Authors

Build Status

Usage

AnyQuery

AnyQuery is a representation of queries for anything. A AnyQuery can be transformed into a NSPredicate and a Dictionary.

let query = AnyQuery.equal(key: "id", value: 1)
query.predicate   //=> NSPredicate(format: "id == 1")
query.dictionary  //=> ["id": 1]

AnyQuery has below types. Each types can be transformed into proper objects

  • equal(key:value:)
  • notEqual(key:value:)
  • greaterThan(key:value:)
  • greaterThanOrEqual(key:value:)
  • lessThan(key:value:)
  • lessThanOrEqual(key:value:)
  • in(key:values:)
  • between(key:lhs:rhs:)

AnyQuery also can be combined with another one with && or || operator.

let query: AnyQuery = .equal(key: "id", value: 1) && .equal(key: "name", value: "naoty")
query.predicate   //=> NSPredicate(format: "id == 1 AND name == naoty")
query.dictionary  //=> ["id": 1, "name": "naoty"]

AnySort

AnySort is a representation of sorts for anything. A AnySort can be transformed into [NSSortDescriptor] and a dictionary.

let sort = AnySort.ascending(key: "id")
sort.sortDescriptors  //=> [NSSortDescriptor(key: "id", ascending: true)]
sort.dictionary       //=> ["sort": ["id"]]

Like AnyQuery, AnySort also can be combined with another one with > operator.

let sort: AnySort = .ascending(key: "name") > .descending(key: "age")
sort.sortDescriptors  //=> [NSSortDescriptor(key: "name", ascending: true), NSSortDescriptor(key: "age", ascending: false)]
sort.dictionary       //=> ["sort": ["name", "-age"]]

Installation

Carthage

github "naoty/AnyQuery"

CocoaPods

pod "AnyQuery"

Author

naoty

Latest podspec

{
    "name": "AnyQuery",
    "version": "0.2.0",
    "summary": "Soft-typed query for anything",
    "description": "Soft-typed query for anything such as Web API and Realm",
    "homepage": "https://github.com/naoty/AnyQuery",
    "license": "MIT",
    "authors": {
        "Naoto Kaneko": "[email protected]"
    },
    "social_media_url": "https://twitter.com/naoty_k",
    "source": {
        "git": "https://github.com/naoty/AnyQuery.git",
        "tag": "0.2.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "AnyQuery/**/*.{h,swift}",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This