You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Core Data Query Interface (CDQI) is a type-safe, fluent, intuitive library for working with Core Data in Swift. CDQI tremendously reduces the amount of code needed to do Core Data, and dramatically improves readability and refactoring by allowing method chaining and by eliminating magic strings.
CDQI uses the PredicateQI (PQI) package. PQI provides a type-safe Swift interface on top of Apple's NSPredicate language. CDQI adds the machinery needed to make PQI work with Core Data.
Given this data model, we can start making some queries. But first, remember to import PredicateQI! Without this import, the compiler magic that allows the comparison expressions to be translated into the NSPredicate language won't work and in most cases you'll get mysterious compilation errors.
import CoreDataQueryInterface
import PredicateQI
// Which languages are known by at least two of the developers?
// developers.@count >= 2
Query(Language.self).filter{ $0.developers.pqiCount >=2}
// Which languages are known by developers whose name contains 's'?
// ANY developers.lastname LIKE[c] '*s*'
Query(Language.self).filter{any(ci($0.developers.lastName %*"*s*"))}
We can get the NSFetchRequest produced by the query by asking for its fetchRequest property. But it's usually easier just to execute the fetch request directly:
import CoreDataQueryInterface
import PredicateQI
letcooldevs=tryQuery(Developer.self).filter{
// ANY languages.name IN {"Rust","Haskell"}
any($0.languages.name <~|["Rust","Haskell"])}.fetch(moc)
About
A type-safe, fluent Swift library for working with Core Data