Skip to content

Commit c0247d9

Browse files
committed
Closed #40
1 parent 8cb7f43 commit c0247d9

File tree

8 files changed

+41
-15
lines changed

8 files changed

+41
-15
lines changed

CoreDataQueryInterface.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@
109109
F39C7A741B718E34008DB31C /* CoreDataQueryInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = F37C46A51B2A780200B35B1B /* CoreDataQueryInterface.h */; settings = {ATTRIBUTES = (Public, ); }; };
110110
F39E485D1CB0208F00A60255 /* NSManagedObjectID.swift in Sources */ = {isa = PBXBuildFile; fileRef = F39E485C1CB0208F00A60255 /* NSManagedObjectID.swift */; };
111111
F39E485E1CB0214900A60255 /* NSManagedObjectID.swift in Sources */ = {isa = PBXBuildFile; fileRef = F39E485C1CB0208F00A60255 /* NSManagedObjectID.swift */; };
112+
F3AE4B191CC960F100AAEE1D /* PredicateComparable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3AE4B181CC960F100AAEE1D /* PredicateComparable.swift */; };
113+
F3AE4B1A1CC960F100AAEE1D /* PredicateComparable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3AE4B181CC960F100AAEE1D /* PredicateComparable.swift */; };
112114
F3E6B5501B2BFCA500F735EE /* FilterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3E6B54F1B2BFCA500F735EE /* FilterTests.swift */; };
113115
F3E6B5511B2BFCA500F735EE /* FilterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3E6B54F1B2BFCA500F735EE /* FilterTests.swift */; };
114116
F3E6B5531B2C01CC00F735EE /* OrderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3E6B5521B2C01CC00F735EE /* OrderTests.swift */; };
@@ -193,6 +195,7 @@
193195
F38B43031CB04AFE0028E515 /* EntityAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EntityAttribute.swift; sourceTree = "<group>"; };
194196
F39C7A711B718DB2008DB31C /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
195197
F39E485C1CB0208F00A60255 /* NSManagedObjectID.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSManagedObjectID.swift; sourceTree = "<group>"; };
198+
F3AE4B181CC960F100AAEE1D /* PredicateComparable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PredicateComparable.swift; sourceTree = "<group>"; };
196199
F3DEBD9F1B40FCCD00EE1382 /* bin */ = {isa = PBXFileReference; lastKnownFileType = folder; path = bin; sourceTree = "<group>"; };
197200
F3E6B54F1B2BFCA500F735EE /* FilterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilterTests.swift; sourceTree = "<group>"; };
198201
F3E6B5521B2C01CC00F735EE /* OrderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderTests.swift; sourceTree = "<group>"; };
@@ -293,6 +296,7 @@
293296
F371ABD51B2BC14A002A8A85 /* Ordering.swift */,
294297
F37A46F41B2BD77900D4EE61 /* Predicate.swift */,
295298
F35DD3671CAF8BC400FB2EF8 /* PredicateBuilder.swift */,
299+
F3AE4B181CC960F100AAEE1D /* PredicateComparable.swift */,
296300
F371ABB71B2BA8BA002A8A85 /* QueryBuilder.swift */,
297301
F371ABC61B2BB80E002A8A85 /* QueryType.swift */,
298302
F371ABDF1B2BC1F7002A8A85 /* Selecting.swift */,
@@ -531,6 +535,7 @@
531535
F371ABBA1B2BA8BA002A8A85 /* QueryBuilder.swift in Sources */,
532536
F371ABE21B2BC1F7002A8A85 /* Selecting.swift in Sources */,
533537
F39E485E1CB0214900A60255 /* NSManagedObjectID.swift in Sources */,
538+
F3AE4B1A1CC960F100AAEE1D /* PredicateComparable.swift in Sources */,
534539
F33863A41C322DB700818352 /* CustomPropertyConvertible.swift in Sources */,
535540
F37A46F21B2BD61700D4EE61 /* Attribute.swift in Sources */,
536541
8EC22BC11CAA3AE400642BB6 /* TypedExpressionConvertible.swift in Sources */,
@@ -595,6 +600,7 @@
595600
F371ABB81B2BA8BA002A8A85 /* QueryBuilder.swift in Sources */,
596601
F371ABE01B2BC1F7002A8A85 /* Selecting.swift in Sources */,
597602
F39E485D1CB0208F00A60255 /* NSManagedObjectID.swift in Sources */,
603+
F3AE4B191CC960F100AAEE1D /* PredicateComparable.swift in Sources */,
598604
F33863A21C322DB700818352 /* CustomPropertyConvertible.swift in Sources */,
599605
F37A46F01B2BD61700D4EE61 /* Attribute.swift in Sources */,
600606
8EC22BBF1CAA37D500642BB6 /* TypedExpressionConvertible.swift in Sources */,

CoreDataQueryInterface/Attribute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import CoreData
2929
The base class for attributes.
3030
- note: Don't use this class directly. Create or use one of its subclasses, such as `KeyAttribute`.
3131
*/
32-
public class Attribute: CustomStringConvertible, CustomExpressionConvertible {
32+
public class Attribute: CustomStringConvertible, CustomExpressionConvertible, PredicateComparable {
3333
private let _name: String?
3434
private let _parent: Attribute?
3535
private let _type: NSAttributeType?

CoreDataQueryInterface/Count.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424

2525
import Foundation
2626

27-
public struct Count: TypedExpressionConvertible, ComparableExpression {
27+
public struct Count: TypedExpressionConvertible, ComparableExpression, PredicateComparable {
2828
public typealias ExpressionValueType = NSNumber
2929
private var parent: CustomExpressionConvertible
3030

CoreDataQueryInterface/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>3.1.1</string>
18+
<string>4.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

CoreDataQueryInterface/Operators.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,42 @@ SOFTWARE.
2424

2525
import Foundation
2626

27-
public func ==<L: TypedExpressionConvertible, R: TypedExpressionConvertible where L.ExpressionValueType == R.ExpressionValueType>(lhs: L, rhs: R) -> NSPredicate {
27+
public func ==<L: PredicateComparable, R: TypedExpressionConvertible where L: TypedExpressionConvertible, L.ExpressionValueType == R.ExpressionValueType>(lhs: L, rhs: R) -> NSPredicate {
2828
return lhs.equalTo(rhs)
2929
}
3030

31-
public func ==<L: TypedExpressionConvertible, RE: TypedExpressionConvertible, R: SequenceType where L.ExpressionValueType == RE.ExpressionValueType, R.Generator.Element == RE>(lhs: L, rhs: R) -> NSPredicate {
31+
public func ==<L: PredicateComparable, RE: TypedExpressionConvertible, R: SequenceType where L: TypedExpressionConvertible, L.ExpressionValueType == RE.ExpressionValueType, R.Generator.Element == RE>(lhs: L, rhs: R) -> NSPredicate {
3232
return lhs.among(rhs)
3333
}
3434

35-
public func ==<L: TypedExpressionConvertible>(lhs: L, rhs: Null) -> NSPredicate {
35+
public func ==<L: PredicateComparable where L: TypedExpressionConvertible>(lhs: L, rhs: Null) -> NSPredicate {
3636
return lhs.equalTo(rhs)
3737
}
3838

39-
public func !=<L: TypedExpressionConvertible, R: TypedExpressionConvertible where L.ExpressionValueType == R.ExpressionValueType>(lhs: L, rhs: R) -> NSPredicate {
39+
public func !=<L: PredicateComparable, R: TypedExpressionConvertible where L: TypedExpressionConvertible, L.ExpressionValueType == R.ExpressionValueType>(lhs: L, rhs: R) -> NSPredicate {
4040
return lhs.notEqualTo(rhs)
4141
}
4242

43-
public func !=<L: TypedExpressionConvertible, RE: TypedExpressionConvertible, R: SequenceType where L.ExpressionValueType == RE.ExpressionValueType, R.Generator.Element == RE>(lhs: L, rhs: R) -> NSPredicate {
43+
public func !=<L: PredicateComparable, RE: TypedExpressionConvertible, R: SequenceType where L: TypedExpressionConvertible, L.ExpressionValueType == RE.ExpressionValueType, R.Generator.Element == RE>(lhs: L, rhs: R) -> NSPredicate {
4444
return !lhs.among(rhs)
4545
}
4646

47-
public func !=<L: TypedExpressionConvertible>(lhs: L, rhs: Null) -> NSPredicate {
47+
public func !=<L: PredicateComparable where L: TypedExpressionConvertible>(lhs: L, rhs: Null) -> NSPredicate {
4848
return lhs.notEqualTo(rhs)
4949
}
5050

51-
public func ><L: TypedExpressionConvertible, R: TypedExpressionConvertible where L.ExpressionValueType == R.ExpressionValueType, L.ExpressionValueType: ComparableExpression>(lhs: L, rhs: R) -> NSPredicate {
51+
public func ><L: PredicateComparable, R: TypedExpressionConvertible where L: TypedExpressionConvertible, L.ExpressionValueType == R.ExpressionValueType, L.ExpressionValueType: ComparableExpression>(lhs: L, rhs: R) -> NSPredicate {
5252
return lhs.greaterThan(rhs)
5353
}
5454

55-
public func >=<L: TypedExpressionConvertible, R: TypedExpressionConvertible where L.ExpressionValueType == R.ExpressionValueType, L.ExpressionValueType: ComparableExpression>(lhs: L, rhs: R) -> NSPredicate {
55+
public func >=<L: PredicateComparable, R: TypedExpressionConvertible where L: TypedExpressionConvertible, L.ExpressionValueType == R.ExpressionValueType, L.ExpressionValueType: ComparableExpression>(lhs: L, rhs: R) -> NSPredicate {
5656
return lhs.greaterThanOrEqualTo(rhs)
5757
}
5858

59-
public func <<L: TypedExpressionConvertible, R: TypedExpressionConvertible where L.ExpressionValueType == R.ExpressionValueType, L.ExpressionValueType: ComparableExpression>(lhs: L, rhs: R) -> NSPredicate {
59+
public func <<L: PredicateComparable, R: TypedExpressionConvertible where L: TypedExpressionConvertible, L.ExpressionValueType == R.ExpressionValueType, L.ExpressionValueType: ComparableExpression>(lhs: L, rhs: R) -> NSPredicate {
6060
return lhs.lessThan(rhs)
6161
}
6262

63-
public func <=<L: TypedExpressionConvertible, R: TypedExpressionConvertible where L.ExpressionValueType == R.ExpressionValueType, L.ExpressionValueType: ComparableExpression>(lhs: L, rhs: R) -> NSPredicate {
63+
public func <=<L: PredicateComparable, R: TypedExpressionConvertible where L: TypedExpressionConvertible, L.ExpressionValueType == R.ExpressionValueType, L.ExpressionValueType: ComparableExpression>(lhs: L, rhs: R) -> NSPredicate {
6464
return lhs.lessThanOrEqualTo(rhs)
6565
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// PredicateComparable.swift
3+
// CoreDataQueryInterface
4+
//
5+
// Created by Gregory Higley on 4/21/16.
6+
// Copyright © 2016 Prosumma LLC. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
/**
12+
Types which implement this protocol can appear on the left-hand
13+
side of an expression that generates a filter predicate.
14+
*/
15+
public protocol PredicateComparable {}

CoreDataQueryInterface/TypedExpressionConvertible.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public protocol TypedExpressionConvertible: CustomExpressionConvertible {
4444

4545
public protocol ComparableExpression { }
4646

47-
extension TypedExpressionConvertible {
47+
extension TypedExpressionConvertible where Self: PredicateComparable {
4848
public func equalTo<R: TypedExpressionConvertible where Self.ExpressionValueType == R.ExpressionValueType>(rhs: R, options: NSComparisonPredicateOptions = []) -> NSPredicate {
4949
return PredicateBuilder.equalTo(lhs: self, rhs: rhs, options: options)
5050
}
@@ -66,7 +66,7 @@ extension TypedExpressionConvertible {
6666
}
6767
}
6868

69-
extension TypedExpressionConvertible where ExpressionValueType: ComparableExpression {
69+
extension TypedExpressionConvertible where Self: PredicateComparable, ExpressionValueType: ComparableExpression {
7070
public func greaterThan<R: TypedExpressionConvertible where Self.ExpressionValueType == R.ExpressionValueType>(rhs: R, options: NSComparisonPredicateOptions = []) -> NSPredicate {
7171
return PredicateBuilder.greaterThan(lhs: self, rhs: rhs, options: options)
7272
}

CoreDataQueryInterfaceTests/SanityTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ import XCTest
2828

2929
class SanityTests: BaseTestCase {
3030

31+
func testThatComplexBooleansStillWork() {
32+
let x = 14
33+
XCTAssertTrue(x > 0 && x < 47)
34+
}
35+
3136
func testCountDepartments() {
3237
let departmentCount = managedObjectContext.from(Department).count()
3338
XCTAssertEqual(departmentCount, 3)

0 commit comments

Comments
 (0)