From d8e27b70ea91ff0877e8fde3d6eaa609f17ed853 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Mon, 7 Aug 2023 23:30:52 +0300 Subject: [PATCH] Fixing binding to wrong view --- Sources/YadUI/Extensions/UIView/UIView+Binding.swift | 4 ++-- Sources/YadUI/Models/BindingModel.swift | 10 +++++----- Sources/YadUI/Views/ContainerView.swift | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/YadUI/Extensions/UIView/UIView+Binding.swift b/Sources/YadUI/Extensions/UIView/UIView+Binding.swift index fbd9fed..c556290 100644 --- a/Sources/YadUI/Extensions/UIView/UIView+Binding.swift +++ b/Sources/YadUI/Extensions/UIView/UIView+Binding.swift @@ -41,9 +41,9 @@ extension UIView { to srcTag: Int, srcProp: KeyPath.Publisher>) -> Self where Dst: InitConvertible, Dst.Param == Src { - bindings.add(BindingModel(srcTag: srcTag, dstTag: tag, bind: { container, srcTag, dstTag in + bindings.add(BindingModel(srcTag: srcTag, dstView: self, bind: { container, srcTag, dstView in guard let srcView = container.viewWithTag(srcTag) as? SrcView, - let dstView = container.viewWithTag(dstTag) as? DstView + let dstView = dstView as? DstView else { return false } diff --git a/Sources/YadUI/Models/BindingModel.swift b/Sources/YadUI/Models/BindingModel.swift index c4b9168..e4bd049 100644 --- a/Sources/YadUI/Models/BindingModel.swift +++ b/Sources/YadUI/Models/BindingModel.swift @@ -5,17 +5,17 @@ // Created by Мустафаев Селим Мустафаевич on 03.08.2023. // -import Foundation +import UIKit class BindingModel { var srcTag: Int - var dstTag: Int - var bind: (ContainerView, Int, Int) -> Bool + weak var dstView: UIView? + var bind: (ContainerView, Int, UIView?) -> Bool - init(srcTag: Int, dstTag: Int, bind: @escaping (ContainerView, Int, Int) -> Bool) { + init(srcTag: Int, dstView: UIView, bind: @escaping (ContainerView, Int, UIView?) -> Bool) { self.srcTag = srcTag - self.dstTag = dstTag + self.dstView = dstView self.bind = bind } } diff --git a/Sources/YadUI/Views/ContainerView.swift b/Sources/YadUI/Views/ContainerView.swift index 37d25df..2e5c141 100644 --- a/Sources/YadUI/Views/ContainerView.swift +++ b/Sources/YadUI/Views/ContainerView.swift @@ -34,7 +34,7 @@ open class ContainerView: UIView { continue } - if !binding.bind(self, binding.srcTag, binding.dstTag) { + if !binding.bind(self, binding.srcTag, binding.dstView) { failedBindings.append(binding) } }