而不是在我的视图控制器中写这个:
@weakify(self);
[[self.view.emailAddressField.rac_textSignal distinctUntilChanged] subscribeNext:^(NSString *emailAddress) {
@strongify(self);
self.viewModel.emailAddress = emailAddress;
}];
使用以下内容会产生什么后果和影响?
RAC(self.viewModel, emailAddress) = [self.view.emailAddressField.rac_textSignal distinctUntilChanged];
答案 0 :(得分:3)
它们是等价的,假设在调用时已经设置了self.viewModel
。
答案 1 :(得分:3)
请阅读源代码。
RAC(target, keyPath, nilValue) = signal;
类似于:
[signal setkeyPath:keyPath onObject:target nilValue:niValue];
和setKeyPath:onObject:nilValue:
的实现方式为:
RACDisposable *subscriptionDisposable = [self subscribeNext:^(id x) {
NSObject *object = (__bridge id)objectPtr;
[object setValue:x ?: nilValue forKeyPath:keyPath];
} error:^(NSError *error) {
...
} completed:^{
...
}];