From e28911721538fa0c2439e92320bad13e3200866f Mon Sep 17 00:00:00 2001 From: Brandon Williams <135203+mbrandonw@users.noreply.github.com> Date: Wed, 18 Dec 2024 19:27:50 -1000 Subject: [PATCH] Implement the Perceptible macro conformance manually (#256) * Manually implement Perceptible conformance. * wip * fix --- Sources/SwiftNavigation/UIBinding.swift | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftNavigation/UIBinding.swift b/Sources/SwiftNavigation/UIBinding.swift index 2489e881e..f9e72d398 100644 --- a/Sources/SwiftNavigation/UIBinding.swift +++ b/Sources/SwiftNavigation/UIBinding.swift @@ -560,11 +560,27 @@ private final class _UIBindingWeakRoot: _UIBinding, @unc } } -@Perceptible -private final class _UIBindingWrapper { - var value: Value +private final class _UIBindingWrapper: Perceptible, Observable { + var _value: Value + var value: Value { + get { + _$perceptionRegistrar.access(self, keyPath: \.value) + return _value + } + set { + _$perceptionRegistrar.withMutation(of: self, keyPath: \.value) { + _value = newValue + } + } + _modify { + _$perceptionRegistrar.willSet(self, keyPath: \.value) + defer { _$perceptionRegistrar.didSet(self, keyPath: \.value) } + yield &_value + } + } + let _$perceptionRegistrar = PerceptionRegistrar() init(_ value: Value) { - self.value = value + self._value = value } }