From fd42466325a4058d73d0f6f28cc73bad2d9e0d74 Mon Sep 17 00:00:00 2001 From: Eric Hovhannisyan Date: Tue, 31 Dec 2024 15:49:52 +0400 Subject: [PATCH] Fix memory weak on webView subscribe --- Sources/WebView/WebView.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/WebView/WebView.swift b/Sources/WebView/WebView.swift index a20b1d8..14fb33b 100644 --- a/Sources/WebView/WebView.swift +++ b/Sources/WebView/WebView.swift @@ -17,9 +17,11 @@ public class WebViewStore: ObservableObject { private func setupObservers() { func subscriber(for keyPath: KeyPath) -> NSKeyValueObservation { - return webView.observe(keyPath, options: [.prior]) { _, change in + return webView.observe(keyPath, options: [.prior]) { [weak self] _, change in + guard let self else { return } + if change.isPrior { - self.objectWillChange.send() + objectWillChange.send() } } }