Skip to content

Commit 5316d7b

Browse files
committed
fix: support optional operators
1 parent 815777d commit 5316d7b

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Master
44

5+
### Bug Fixes
6+
7+
* Prevents fatal error when handling operators with optional `Date` types.
8+
9+
## 0.14.0
10+
511
### Breaking
612

713
* Drops support for Swift 3 and Swift 4. Swift 5 or newer must be used.

Sources/QueryKit/Attribute.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ public struct Attribute<AttributeType> : Equatable {
4343
}
4444
}
4545

46-
let value = unsafeBitCast(value, to: Optional<String>.self)
47-
if let value = value {
48-
return NSExpression(forConstantValue: value)
49-
}
46+
return NSExpression(forConstantValue: value)
5047
}
5148

5249
return NSExpression(forConstantValue: NSNull())

Tests/QueryKitTests/KeyPathTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ class KeyPathTests: XCTestCase {
1212
XCTAssertEqual(predicate.predicate, NSPredicate(format:"name == %@", NSNull()))
1313
}
1414

15+
func testOptionalEqualityOperatorWithOptional() {
16+
let predicate: Predicate<User> = \User.createdAt == nil
17+
XCTAssertEqual(predicate.predicate, NSPredicate(format:"createdAt == %@", NSNull()))
18+
}
19+
1520
func testInequalityOperator() {
1621
let predicate: Predicate<User> = \User.name != "kyle"
1722
XCTAssertEqual(predicate.predicate, NSPredicate(format:"name != 'kyle'"))
@@ -118,4 +123,5 @@ class KeyPathNSPredicateTests: XCTestCase {
118123
class User: NSManagedObject {
119124
@objc var name: String?
120125
@NSManaged var age: Int
126+
@objc var createdAt: Date?
121127
}

0 commit comments

Comments
 (0)