Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TheOtherSideOfTheSea opened this issue Jun 28, 2021 · 3 comments
Open

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

TheOtherSideOfTheSea opened this issue Jun 28, 2021 · 3 comments

Comments

@TheOtherSideOfTheSea
Copy link

No description provided.

@shidavid
Copy link
Owner

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

@TheOtherSideOfTheSea
Copy link
Author

TheOtherSideOfTheSea commented Jun 28, 2021

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方法没有第二个参数

@shidavid
Copy link
Owner

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants