如何使用Bond框架绑定不同的属性类型



我有一个标签(字符串),我的对象有一个NSNumber属性。

如何使用双向绑定(双向绑定)绑定不同的属性类型?

例如:

框架债券:https://github.com/SwiftBond/Bond

protocol NewTransactionViewModelProtocol
{
    var Price: Observable<NSNumber?>;
}
class NewTransactionView: UIViewController
{
    @IBOutlet weak var PriceLabel: UILabel!
    var viewModel: NewTransactionViewModelProtocol! 
    {
        didSet 
        {
            viewModel.Price.bidirectionalBindTo(self.PriceLabel.bnd_text); //WRONG
        }
    }
}
PS: PriceLabel.bnd_text : Observable<NSString?> 

要将兼容类型A的任何对象转换为B,只需执行以下操作:

A(B)

在您的示例中,您想要做的是:

viewModel.Price.bidirectionalBindTo(NSNumber(self.PriceLabel.bnd_text));

最新更新