當我要控制一個按鈕是否有效和添加按鈕事件時ide
這樣寫會出錯:blog
//當兩個輸入框有值的時候,按鈕纔有效 RAC(self.sendBtn, enabled) = [RACSignal combineLatest: @[self.passwordOldTxt.rac_textSignal,self.passwordTxt.rac_textSignal] reduce:^id(NSString *passwordOld, NSString *password){ return @(passwordOld.length > 0 && password.length > 0); }]; @weakify(self); self.sendBtn.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) { @strongify(self); NSLog(@"self.sendBtn.rac_command TouchUpInside %@", self.title); return [RACSignal empty]; }];
由於ReactiveCocoa把Enabled和Command都整合了事件
因此要寫爲input
@weakify(self); self.sendBtn.rac_command = [[RACCommand alloc] initWithEnabled: [RACSignal combineLatest: @[self.passwordOldTxt.rac_textSignal,self.passwordTxt.rac_textSignal] reduce:^id(NSString *passwordOld, NSString *password){ return @(passwordOld.length > 0 && password.length > 0); }] signalBlock:^RACSignal *(id input) { @strongify(self); NSLog(@"self.sendBtn.rac_command TouchUpInside %@", self.title); return [RACSignal empty]; }];