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
Copy file name to clipboardExpand all lines: README.md
+15-4Lines changed: 15 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,15 +11,18 @@ Core Data Query Interface (CDQI) is a type-safe, fluent, intuitive library for w
11
11
-[x] Optionally eliminates the use of magic strings so common in Core Data
12
12
-[x] Query reuse, i.e., no side-effects from chaining
13
13
-[x] Support for iOS 9+, macOS 10.11+, tvOS 9+, and watchOS 2+.
14
+
-[x] Swift 3 (for Swift 2.2, use v4.0)
14
15
15
16
### Overview
16
17
17
18
In essence, CDQI is a tool that allows the creation (and execution) of fetch requests using a fluent syntax. In most cases, this can reduce many lines of code to a single (but still highly readable) line.
18
19
19
20
```swift
20
-
let swiftDevelopers = managedObjectContext.from(Developer).
21
+
let swiftDevelopers = managedObjectContext.from(Developer.self).
21
22
filter{ any($0.languages.name=="Swift") }.
22
-
order(descending: {$0.lastName}).limit(5).all()
23
+
order(ascending: false, {$0.lastName})
24
+
.limit(5)
25
+
.all()
23
26
```
24
27
25
28
### Integration
@@ -40,7 +43,15 @@ Add the following to your `Podfile`. If it isn't already present, you will have
40
43
pod 'CoreDataQueryInterface', '~> 5.0'
41
44
```
42
45
43
-
#### Attribute Proxies
46
+
### Changes From Previous Versions
47
+
48
+
The overall syntax of CDQI is unchanged from previous versions, as the examples in this document show. But there are small changes.
49
+
50
+
First, `EntityQuery`, `ExpressionQuery` and the like are gone, replaced by a single type `Query<M, R>`. The first generic parameter is the type of managed object model to work with. The second parameter is the result type, which must conform to the `NSFetchResultType` protocol. So instead of saying `EntityQuery.from(Project.self)` we say `Query<Project, NSDictionary>.from(Project.self)`.
51
+
52
+
The second major difference is the use of prefixes on methods, properties, and type aliases. CDQI extends types like `String`,
53
+
54
+
### Attribute Proxies
44
55
45
56
In order to use expressions such as `$0.languages.name` as in the example above, proxy objects must be created. In the `bin` folder at the root of the project is a simple tool called `cdqi` that accomplishes this. Before running this tool, make sure that each `NSManagedObject` is represented by a corresponding class in your Swift project.
46
57
@@ -115,7 +126,7 @@ A great number of examples can be found in the unit tests and the "Top Hits" exa
115
126
let developerQuery = managedObjectContext.from(Developer.self)
116
127
// predicate: languages.@count == 3 AND ANY languages.name == "Rust"
117
128
// developersWhoKnowThreeLanguagesIncludingRust is an array of Developer entities
118
-
let developersWhoKnowThreeLanguagesIncludingRust = developerQuery.filter{ $0.languages.count==3&&
129
+
let developersWhoKnowThreeLanguagesIncludingRust = developerQuery.filter{ $0.languages.cdqiCount()==3&&
0 commit comments