ReactiveCocoaノート3
1400 ワード
RACのいくつかの使い方
1.KVOの代わりに
[self.view rac_observeKeyPath:@"frame" options:NSKeyValueObservingOptionNew observer:nil block:^(id value, NSDictionary *change, BOOL causedByDealloc, BOOL affectedOnlyLastComponent) {
}];
[[self.view rac_valuesForKeyPath:@"frame" observer:nil] subscribeNext:^(id x) {
}];
2.リスニングイベント
[[_btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
NSLog(@" ");
}];
3.代替通知
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIKeyboardWillShowNotification object:nil] subscribeNext:^(id x) {
NSLog(@" ");
}];
4.テキストボックスの変更を傍受する
[_textField.rac_textSignal subscribeNext:^(id x) {
NSLog(@"%@", x);
}];
5.代替エージェント
// 1. :1.RACSubject 2.rac_signalForSelector
// , RACSubject
[[_redView rac_signalForSelector:@selector(btnClick:)] subscribeNext:^(id x) {
NSLog(@" ");
}];