Skip to content

Commit 7c14ac8

Browse files
committed
Handle optionals in Key paths
1 parent 5779429 commit 7c14ac8

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

Sources/SafeFetching/Extensions/KeyPath+Extensions.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ extension KeyPath where Root: NSObject {
1111
var label: Substring {
1212
let description = String(describing: self)
1313
let prefixToDrop = "\\\(Root.self)."
14-
return description.dropFirst(prefixToDrop.count)
14+
var value = description.dropFirst(prefixToDrop.count)
15+
value.removeAll { $0 == "?" }
16+
return value
1517
}
1618
}

Tests/SafeFetchingTests/BooleanPredicateBuilderTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ final class BooleanPredicateTests: XCTestCase {
2727
testNSFormat(predicate: \.stubDate == date, expecting: #"stubDate == CAST(\#(date.timeIntervalSinceReferenceDate), "NSDate")"#)
2828

2929
testNSFormat(predicate: \.stubRelationship == nil, expecting: "stubRelationship == nil")
30+
testNSFormat(predicate: \.stubRelationship?.property == "Toto", expecting: #"stubRelationship.property == "Toto""#)
3031
}
3132

3233
func testString() {

0 commit comments

Comments
 (0)