RAC转换传统的通信

时间:2023-03-10 03:11:17
RAC转换传统的通信

///////////////////各种机制转信号///////////////////////////////

1.UI事件

[self.logInButton rac_signalForControlEvents:UIControlEventTouchUpInside]

2.Delegate回调

[self rac_signalForSelector:@selector(flickrAPIRequest:didCompleteWithResponse:) fromProtocol:@protocol(OFFlickrAPIRequestDelegate)];

3.Notificaiton

[NSNotificationCenter.defaultCenter rac_addObserverForName:UserDidLogOutNotification object:nil]

4.KVO观察

[RACObserve(self, username)]

5.Target-Action

[self rac_signalForSelector:@selector(didChangeValueForKey:)]

////////////////////常用情景//////////////////////////////////

 6.AlertView

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"Alert" delegate:nil cancelButtonTitle:@"YES" otherButtonTitles:@"NO", nil];
[[alertView rac_buttonClickedSignal] subscribeNext:^(NSNumber *indexNumber) {
if ([indexNumber intValue] == ) {
NSLog(@"you touched NO");
} else {
NSLog(@"you touched YES");
}
}];
[alertView show];

7.Gesture

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] init];
tapGesture.numberOfTapsRequired = ;
[[tapGesture rac_gestureSignal] subscribeNext:^(id x) {
[self.viewModel.likeCommand execute:nil];
}];