File tree 1 file changed +18
-5
lines changed
1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -474,12 +474,21 @@ public protocol KeyPathRecordingOptional {
474
474
475
475
subscript< U> ( __unwrap path: WritableKeyPath < Wrapped , U > ) -> U ? { get set }
476
476
477
- subscript< U> ( __unsafe_unwrap path: WritableKeyPath < Wrapped , U > ) -> U { get set }
477
+ subscript< U> ( __unsafe_unwrap path: WritableKeyPath < Wrapped , U ? > ) -> U ? { get set }
478
478
479
479
}
480
480
481
481
extension Optional : KeyPathRecordingOptional {
482
482
483
+ public var asOptional : Wrapped ? {
484
+ get {
485
+ self
486
+ }
487
+ set {
488
+ self = newValue
489
+ }
490
+ }
491
+
483
492
/**
484
493
Do not use.
485
494
*/
@@ -513,10 +522,13 @@ extension Optional: KeyPathRecordingOptional {
513
522
deprecated: 0.1 ,
514
523
message: " An implementation detail of KeyPathRecording. Don't use this yourself. "
515
524
)
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 ? {
518
526
get {
519
- fatalError ( )
527
+ if let wrapped = self {
528
+ return wrapped [ keyPath: path]
529
+ } else {
530
+ return nil
531
+ }
520
532
}
521
533
set {
522
534
if var wrapped = self {
@@ -549,6 +561,7 @@ public extension Recorder where Child: KeyPathRecordingOptional {
549
561
)
550
562
)
551
563
}
552
-
564
+
553
565
}
554
566
567
+
You can’t perform that action at this time.
0 commit comments