Skip to content

Commit eb6f63f

Browse files
committed
NSExpressionDescription
1 parent 71a15a0 commit eb6f63f

File tree

6 files changed

+28
-22
lines changed

6 files changed

+28
-22
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// NSExpressionDescription.swift
3+
// CoreDataQueryInterface
4+
//
5+
// Created by Gregory Higley on 2022-10-25.
6+
//
7+
8+
import CoreData
9+
import PredicateQI
10+
11+
public extension NSExpressionDescription {
12+
convenience init<M: NSObject, V: Expression>(
13+
objectKeyPath keyPath: KeyPath<Object<M>, V>,
14+
name: String,
15+
type: NSAttributeDescription.AttributeType
16+
) {
17+
self.init()
18+
self.expression = Object<M>()[keyPath: keyPath].pqiExpression
19+
self.name = self.name
20+
self.resultType = type
21+
}
22+
}

Sources/CoreDataQueryInterface/NSSortDescriptor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import Foundation
99
import PredicateQI
1010

1111
public extension NSSortDescriptor {
12-
convenience init<M: NSObject, V: Expression>(objectKeyPath: KeyPath<Object<M>, V>, ascending: Bool) {
13-
let expression = Object<M>()[keyPath: objectKeyPath].pqiExpression
12+
convenience init<M: NSObject, V: Expression>(objectKeyPath keyPath: KeyPath<Object<M>, V>, ascending: Bool) {
13+
let expression = Object<M>()[keyPath: keyPath].pqiExpression
1414
self.init(key: expression.keyPath, ascending: ascending)
1515
}
1616
}

Sources/CoreDataQueryInterface/QueryBuilder+Group.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ public extension QueryBuilder {
2626
}
2727

2828
func group<V: Expression>(by keyPath: KeyPath<Object<M>, V>, name: String, type: NSAttributeDescription.AttributeType) -> QueryBuilder<M, R> {
29-
let description = NSExpressionDescription()
30-
description.expression = Object<M>()[keyPath: keyPath].pqiExpression
31-
description.resultType = type
32-
description.name = name
33-
return group(by: description)
29+
return group(by: NSExpressionDescription(objectKeyPath: keyPath, name: name, type: type))
3430
}
3531

3632
func group<V: Expression>(by keyPath: KeyPath<Object<M>, V>) -> QueryBuilder<M, R> {

Sources/CoreDataQueryInterface/QueryBuilder+Group.swift.gyb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ public extension QueryBuilder {
3131
}
3232

3333
func group<V: Expression>(by keyPath: KeyPath<Object<M>, V>, name: String, type: NSAttributeDescription.AttributeType) -> QueryBuilder<M, R> {
34-
let description = NSExpressionDescription()
35-
description.expression = Object<M>()[keyPath: keyPath].pqiExpression
36-
description.resultType = type
37-
description.name = name
38-
return group(by: description)
34+
return group(by: NSExpressionDescription(objectKeyPath: keyPath, name: name, type: type))
3935
}
4036

4137
func group<V: Expression>(by keyPath: KeyPath<Object<M>, V>) -> QueryBuilder<M, R> {

Sources/CoreDataQueryInterface/QueryBuilder+Select.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ public extension QueryBuilder {
3333
}
3434

3535
func select<V: Expression>(_ keyPath: KeyPath<Object<M>, V>, name: String, type: NSAttributeDescription.AttributeType) -> QueryBuilder<M, R> {
36-
let description = NSExpressionDescription()
37-
description.expression = Object<M>()[keyPath: keyPath].pqiExpression
38-
description.resultType = type
39-
description.name = name
40-
return select(description)
36+
select(NSExpressionDescription(objectKeyPath: keyPath, name: name, type: type))
4137
}
4238

4339
func select<V: Expression>(_ keyPath: KeyPath<Object<M>, V>) -> QueryBuilder<M, R> {

Sources/CoreDataQueryInterface/QueryBuilder+Select.swift.gyb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ public extension QueryBuilder {
3838
}
3939

4040
func select<V: Expression>(_ keyPath: KeyPath<Object<M>, V>, name: String, type: NSAttributeDescription.AttributeType) -> QueryBuilder<M, R> {
41-
let description = NSExpressionDescription()
42-
description.expression = Object<M>()[keyPath: keyPath].pqiExpression
43-
description.resultType = type
44-
description.name = name
45-
return select(description)
41+
select(NSExpressionDescription(objectKeyPath: keyPath, name: name, type: type))
4642
}
4743

4844
func select<V: Expression>(_ keyPath: KeyPath<Object<M>, V>) -> QueryBuilder<M, R> {

0 commit comments

Comments
 (0)