Skip to content

Commit 895c828

Browse files
committed
CDQI v5
1 parent aa41b82 commit 895c828

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

CoreDataQueryInterface/Query.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,40 +50,40 @@ public struct Query<M: NSManagedObject, R: NSFetchRequestResult> where M: Entity
5050
public func select<P: Sequence>(_ properties: P) -> Query<M, NSDictionary> where P.Iterator.Element: PropertyConvertible {
5151
var builder = self.builder
5252
builder.resultType = .dictionaryResultType
53-
builder.properties ??= []
54-
builder.properties!.append(contentsOf: properties.map{ $0.cdqiProperty })
53+
builder.propertiesToFetch ??= []
54+
builder.propertiesToFetch!.append(contentsOf: properties.map{ $0.cdqiProperty })
5555
return Query<M, NSDictionary>(builder: builder)
5656
}
5757

5858
public func select(_ properties: PropertyConvertible...) -> Query<M, NSDictionary> {
5959
var builder = self.builder
6060
builder.resultType = .dictionaryResultType
61-
builder.properties ??= []
62-
builder.properties!.append(contentsOf: properties.map{ $0.cdqiProperty })
61+
builder.propertiesToFetch ??= []
62+
builder.propertiesToFetch!.append(contentsOf: properties.map{ $0.cdqiProperty })
6363
return Query<M, NSDictionary>(builder: builder)
6464
}
6565

6666
public func select(_ blocks: ((M.CDQIAttribute) -> PropertyConvertible)...) -> Query<M, NSDictionary> {
6767
var builder = self.builder
6868
builder.resultType = .dictionaryResultType
69-
builder.properties ??= []
69+
builder.propertiesToFetch ??= []
7070
let attribute = M.CDQIAttribute()
71-
builder.properties!.append(contentsOf: blocks.map{ $0(attribute).cdqiProperty })
71+
builder.propertiesToFetch!.append(contentsOf: blocks.map{ $0(attribute).cdqiProperty })
7272
return Query<M, NSDictionary>(builder: builder)
7373
}
7474

7575
public func select(_ block: (M.CDQIAttribute) -> [PropertyConvertible]) -> Query<M, NSDictionary> {
7676
var builder = self.builder
7777
builder.resultType = .dictionaryResultType
78-
builder.properties ??= []
79-
builder.properties!.append(contentsOf: block(M.CDQIAttribute()).map{ $0.cdqiProperty })
78+
builder.propertiesToFetch ??= []
79+
builder.propertiesToFetch!.append(contentsOf: block(M.CDQIAttribute()).map{ $0.cdqiProperty })
8080
return Query<M, NSDictionary>(builder: builder)
8181
}
8282

8383
public func reselect() -> Query<M, NSDictionary> {
8484
var builder = self.builder
8585
builder.resultType = .dictionaryResultType
86-
builder.properties = nil
86+
builder.propertiesToFetch = nil
8787
return Query<M, NSDictionary>(builder: builder)
8888
}
8989

@@ -170,15 +170,15 @@ public struct Query<M: NSManagedObject, R: NSFetchRequestResult> where M: Entity
170170

171171
public func objects() -> Query<M, M> {
172172
var builder = self.builder
173-
builder.properties = nil
173+
builder.propertiesToFetch = nil
174174
builder.propertiesToGroupBy = nil
175175
builder.resultType = .managedObjectResultType
176176
return Query<M, M>(builder: builder)
177177
}
178178

179179
public func ids() -> Query<M, NSManagedObjectID> {
180180
var builder = self.builder
181-
builder.properties = nil
181+
builder.propertiesToFetch = nil
182182
builder.propertiesToGroupBy = nil
183183
builder.resultType = .managedObjectIDResultType
184184
return Query<M, NSManagedObjectID>(builder: builder)

CoreDataQueryInterface/QueryBuilder.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public struct QueryBuilder<M: NSManagedObject> {
1414
public var fetchLimit: Int = 0
1515
public var fetchOffset: Int = 0
1616
public var predicates = [NSPredicate]()
17-
public var properties: [Any]?
17+
public var propertiesToFetch: [Any]?
1818
public var propertiesToGroupBy: [Any]?
1919
public var resultType: NSFetchRequestResultType = .managedObjectResultType
2020
public var sortDescriptors = [NSSortDescriptor]()
@@ -29,10 +29,9 @@ public struct QueryBuilder<M: NSManagedObject> {
2929
request.fetchOffset = fetchOffset
3030
request.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: predicates)
3131
request.sortDescriptors = sortDescriptors
32-
request.propertiesToFetch = properties
32+
request.propertiesToFetch = propertiesToFetch
3333
request.propertiesToGroupBy = propertiesToGroupBy
3434
request.resultType = resultType
35-
NSLog("%@", request)
3635
return request
3736
}
3837

@@ -41,7 +40,6 @@ public struct QueryBuilder<M: NSManagedObject> {
4140
return request(entity: M.entity())
4241
}
4342

44-
@available(*, deprecated: 5.0)
4543
public func request<R>(managedObjectModel: NSManagedObjectModel) -> NSFetchRequest<R> {
4644
return request(entity: M.cdqiEntity(managedObjectModel: managedObjectModel))
4745
}

0 commit comments

Comments
 (0)