DVDataBind icon indicating copy to clipboard operation
DVDataBind copied to clipboard

请问swift 能用这个进行双向绑定么

Open TheOtherSideOfTheSea opened this issue 4 years ago • 3 comments

TheOtherSideOfTheSea avatar Jun 28 '21 08:06 TheOtherSideOfTheSea

Swift也能使用, 只不过更新数据不能直接 object.property = xxx , 需要 object.setValue(xxx, forKey: "property")

shidavid avatar Jun 28 '21 08:06 shidavid

Swift也使用,但更新数据不能直接对象.property = xxx,需要 object.setValue(xxx, forKey: "property")

oc中的绑定是这样的 DVDataBind ._inout(self.demoModel, @"text") ._inout_ui(self.demoView.textField, @"text", UIControlEventEditingChanged) ._out(self.demoView.label, @"text") ._out_key_any(@"com.text", ^(NSString *text) { NSString *pText = weakSelf.demoModel.text; NSLog(@"demoModel 最新值为 %@", pText); });

[self.demoView.button addTarget:self
                         action:@selector(onClickForButton:)
               forControlEvents:UIControlEventTouchUpInside];

那么,在swift中应该怎么写绑定这块?image swift中DavDataBind._inout方法没有第二个参数

TheOtherSideOfTheSea avatar Jun 28 '21 08:06 TheOtherSideOfTheSea

Swift也使用,但更新数据不能直接对象.property = xxx,需要 object.setValue(xxx, forKey: "property")

oc中的绑定是这样的 DVDataBind ._inout(self.demoModel, @"text") ._inout_ui(self.demoView.textField, @"text", UIControlEventEditingChanged) ._out(self.demoView.label, @"text") ._out_key_any(@"com.text", ^(NSString *text) { NSString *pText = weakSelf.demoModel.text; NSLog(@"demoModel 最新值为 %@", pText); });

[self.demoView.button addTarget:self
                         action:@selector(onClickForButton:)
               forControlEvents:UIControlEventTouchUpInside];

那么,在swift中应该怎么写绑定这块?image swift中DavDataBind._inout方法没有第二个参数

let view : UIView = UIView() MyDataBind ._in()(self, "hello") ._inout_ui()(view, "property", UIControlEvents.touchUpInside) // 比OC多加一个()

这里必须用 .setValue设值,不能 view.property 直接赋值 view.setValue("123", forKey: "property") self.setValue("456", forKey: "hello")

shidavid avatar Jun 30 '21 06:06 shidavid