Skip to content

Commit ffeaf15

Browse files
committedDec 29, 2020
fix build without fatalerror
1 parent 34cefdc commit ffeaf15

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed
 

‎Sources/KeyPathRecording/KeyPathRecording.swift

+18-5
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,21 @@ public protocol KeyPathRecordingOptional {
474474

475475
subscript<U>(__unwrap path: WritableKeyPath<Wrapped, U>) -> U? { get set }
476476

477-
subscript<U>(__unsafe_unwrap path: WritableKeyPath<Wrapped, U>) -> U { get set }
477+
subscript<U>(__unsafe_unwrap path: WritableKeyPath<Wrapped, U?>) -> U? { get set }
478478

479479
}
480480

481481
extension Optional: KeyPathRecordingOptional {
482482

483+
public var asOptional: Wrapped? {
484+
get {
485+
self
486+
}
487+
set {
488+
self = newValue
489+
}
490+
}
491+
483492
/**
484493
Do not use.
485494
*/
@@ -513,10 +522,13 @@ extension Optional: KeyPathRecordingOptional {
513522
deprecated: 0.1,
514523
message: "An implementation detail of KeyPathRecording. Don't use this yourself."
515524
)
516-
public subscript<U>(__unsafe_unwrap path: WritableKeyPath<Wrapped, U>) -> U {
517-
@available(*, unavailable)
525+
public subscript<U>(__unsafe_unwrap path: WritableKeyPath<Wrapped, U?>) -> U? {
518526
get {
519-
fatalError()
527+
if let wrapped = self {
528+
return wrapped[keyPath: path]
529+
} else {
530+
return nil
531+
}
520532
}
521533
set {
522534
if var wrapped = self {
@@ -549,6 +561,7 @@ public extension Recorder where Child: KeyPathRecordingOptional {
549561
)
550562
)
551563
}
552-
564+
553565
}
554566

567+

0 commit comments

Comments
 (0)