ReactiveCocoa 첫 경험
Case 0.기본 - subscribeNext 응용 프로그램: VC에서viewModel에 바인딩된 error=> 오류 처리
@weakify(self);
[RACObserve(self.viewModel, error) subscribeNext:^(id x) {
@strongify(self);
if (self.viewModel.error) {
[self showExceptionEmptyView:self.viewModel.error];
}
}];
Case 1.RAC&combineLatest & reduce 응용 프로그램: 로그인 페이지의 로그인 단추와 사용자 이름 & 암호 상자에 입력한 내용 연결
RAC(self.sureBtn,enabled) = [RACSignal combineLatest:@[self.passWordTextField.rac_textSignal,
self.surePassWordTextField.rac_textSignal,
self.codeTextField.rac_textSignal
]
reduce:^(NSString *passWord, NSString *surePassWord, NSString *codeText){
BOOL enabled = (passWord.length > 0 && surePassWord.length > 0 && codeText.length > 0)? YES:NO;
self.sureBtn.backgroundColor = enabled ? [UIColor colorWithHex:0x008EFF]:[UIColor colorWithHex:0x797979];
return @(enabled);
}];
Case 2.rac_command - UIControl's RAC Support Category. More convenient to write the action code of UIControls without delegate.
DDViolationInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([DDViolationInfoCell class])
forIndexPath:indexPath];
@weakify(self);
cell.showReasonBtn.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input){
@strongify(self);
return [RACSignal defer:^RACSignal *(){
// Btn Action
return [RACSignal empty];
}];
}];
@weakify(self);
[self.lv2ItemPriceTextField.rac_textSignal subscribeNext:^(NSString *newText) {
@strongify(self);
NSString *tempStr = [NSString stringWithFormat:@"%0.2f", [newText floatValue]];
self.lv2ItemModel.price = [tempStr floatValue];
}];
Case 3.절전 밸브-throttle 응용: 윤문 요청
@weakify(self);
self.violationInfoUpdatedSignal = [[RACObserve(self.viewModel, violationInfo) throttle:2.0] subscribeNext:^(id x) {
@strongify(self);
if (x) {
if (4 == self.viewModel.violationInfo.code && self.viewModel.violationInfoCheckTimes < 10) { // 2
self.viewModel.violationInfoCheckTimes ++;
[self.viewModel requestViolationInfoWithVehicle:self.viewModel.violationBasicInfo.vehicle
ein:self.viewModel.violationBasicInfo.ein
vin:self.viewModel.violationBasicInfo.vin
areas:self.viewModel.violationBasicInfo.areas];
} else if (self.viewModel.isShowViolationCarInfoErrorPage) { //
[self showExceptionEmptyView:nil];
} else { // &
}
}];
//
[self.violationInfoUpdatedSignal dispose];
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.