Fixing binding to wrong view

This commit is contained in:
Selim Mustafaev 2023-08-07 23:30:52 +03:00
parent 1a4abe5a56
commit d8e27b70ea
3 changed files with 8 additions and 8 deletions

View File

@ -41,9 +41,9 @@ extension UIView {
to srcTag: Int,
srcProp: KeyPath<SrcView,Published<Src>.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
}

View File

@ -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
}
}

View File

@ -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)
}
}