Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kishikawakatsumi/Kuery
A type-safe Core Data query API using Swift 4's Smart KeyPaths
https://github.com/kishikawakatsumi/Kuery
Last synced: 3 months ago
JSON representation
A type-safe Core Data query API using Swift 4's Smart KeyPaths
- Host: GitHub
- URL: https://github.com/kishikawakatsumi/Kuery
- Owner: kishikawakatsumi
- License: mit
- Created: 2017-06-14T09:55:58.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-07T06:40:25.000Z (about 6 years ago)
- Last Synced: 2024-07-06T23:41:56.061Z (4 months ago)
- Language: Swift
- Size: 38.1 KB
- Stars: 618
- Watchers: 19
- Forks: 13
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kuery
Kuery, a type-safe Core Data query API using Swift 4's Smart KeyPaths. Inspired and borrowed a lot of things from [QueryKit](https://github.com/QueryKit/QueryKit) and [RealmEx](https://github.com/koher/RealmEx).
## Requirements
Kuery is written in Swift 4.## Installation
### CocoaPods
Kuery is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'Kuery'
```### Carthage
For [Carthage](https://github.com/Carthage/Carthage), add the following to your `Cartfile`:```ogdl
github "kishikawakatsumi/Kuery"
```## Description
Kuery provides type safety, code completion and avoidance of typos against `NSPredicate` queries.
### Before
```swift
NSPredicate(format: "name == %@", "Katsumi")
NSPredicate(format: "age > %@", 20)
```### After
```swift
Query(Person.self).filter(\Person.name == "Katsumi")
Query(Person.self).filter(\Person.age > 20)
```The following code should be a compile error.
```swift
Query(Person.self).filter(\Person.name > 20) // Compile error
Query(Person.self).filter(\Dog.name == "John") // Compile error
```## Usage
```Swift
context.perform {
let results = try Query(Person.self)
.filter(\Person.name == "Katsumi")
.execute()
}
``````Swift
context.perform {
let results = try Query(Person.self)
.filter(\Person.age == 36)
.execute()
}
``````Swift
context.perform {
let results = try Query(Person.self)
.filter(\Person.age > 20)
.execute()
}
``````Swift
context.perform {
let results = try Query(Person.self)
.filter(\Person.name == "Katsumi")
.filter(\Person.age == 36)
.execute()
}
``````Swift
context.perform {
let results = try Query(Dog.self)
.filter(\Dog.owner == person)
.execute()
}
```### Feature request for Swift Standard Library
It requires a string representation of `KeyPath` to construct `NSPredicate` from `KeyPath`. However, the API is not officially visible currently. The feature request is tracked at [SR-5220](https://bugs.swift.org/browse/SR-5220).
[[SR-5220] Expose API to retrieve string representation of KeyPath - Swift](https://bugs.swift.org/browse/SR-5220)