内容
RACKVOChannel 的作用
RACKVOChannel 的作用使用 RACKVOChannel 实现双向绑定
RACKVOChannel 实现双向绑定// 假设 ViewModel 有一个 name 属性
@interface ViewModel : NSObject
@property (nonatomic, strong) NSString *name;
@end
@implementation ViewModel
@end
// 在 ViewController 中使用 RACKVOChannel 进行绑定
@interface ViewController : UIViewController
@property (nonatomic, strong) ViewModel *viewModel;
@property (nonatomic, strong) UITextField *nameTextField;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.viewModel = [[ViewModel alloc] init];
self.nameTextField = [[UITextField alloc] init];
// 使用 RACKVOChannel 进行双向绑定
RACChannelTo(self.viewModel, name) = self.nameTextField.rac_newTextChannel;
}
@end代码解析
RACKVOChannel 和 RACChannelTo 的关系
RACKVOChannel 和 RACChannelTo 的关系使用场景
总结
Last updated