@@ -440,6 +440,25 @@ public struct UIBinding<Value>: Sendable {
440
440
binding. transaction = transaction
441
441
return binding
442
442
}
443
+
444
+ public func _printChanges(
445
+ _ prefix: String = " " ,
446
+ fileID: StaticString = #fileID,
447
+ line: UInt = #line
448
+ ) -> Self {
449
+ func open( _ location: some _UIBinding < Value > ) -> Self {
450
+ Self (
451
+ location: _UIBindingPrintChanges (
452
+ base: location,
453
+ prefix: prefix,
454
+ fileID: fileID,
455
+ line: line
456
+ ) ,
457
+ transaction: transaction
458
+ )
459
+ }
460
+ return open ( location)
461
+ }
443
462
}
444
463
445
464
extension UIBinding : Identifiable where Value: Identifiable {
@@ -793,3 +812,38 @@ private final class _UIBindingOptionalEnumToCase<
793
812
hasher. combine ( keyPath)
794
813
}
795
814
}
815
+
816
+ private final class _UIBindingPrintChanges < Base: _UIBinding > : _UIBinding , @unchecked Sendable {
817
+ let base : Base
818
+ let prefix : String
819
+ let fileID : StaticString
820
+ let line : UInt
821
+ init ( base: Base , prefix: String , fileID: StaticString , line: UInt ) {
822
+ self . base = base
823
+ self . prefix = prefix
824
+ self . fileID = fileID
825
+ self . line = line
826
+ }
827
+ var wrappedValue : Base . Value {
828
+ get { base. wrappedValue }
829
+ set {
830
+ var oldDescription = " "
831
+ debugPrint ( base. wrappedValue, terminator: " " , to: & oldDescription)
832
+ var newDescription = " "
833
+ debugPrint ( newValue, terminator: " " , to: & newDescription)
834
+ print (
835
+ " \( prefix. isEmpty ? " UIBinding< \( Value . self) >@ \( fileID) : \( line) " : prefix) : " ,
836
+ oldDescription,
837
+ " → " ,
838
+ newDescription
839
+ )
840
+ base. wrappedValue = newValue
841
+ }
842
+ }
843
+ static func == ( lhs: _UIBindingPrintChanges , rhs: _UIBindingPrintChanges ) -> Bool {
844
+ lhs. base == rhs. base
845
+ }
846
+ func hash( into hasher: inout Hasher ) {
847
+ hasher. combine ( base)
848
+ }
849
+ }
0 commit comments