ReactiveObjC unifies disparate Cocoa APIs like UI callbacks, network responses, and KVO notifications into RACSignal objects. This allows you to compose them using operators like combineLatest:, RACObserve, and rac_signalForControlEvents:.
Key patterns include:
- Using
RACObserve(object, keyPath) for KVO. - Using
rac_addObserverForName:object: for NSNotificationCenter. - Using
rac_textSignal for text field changes. - Using
rac_signalForControlEvents: for UI events.
// Example: Combining multiple signals to drive UI state
@weakify(self);
RAC(self.logInButton, enabled) = [RACSignal
combineLatest:@[
self.usernameTextField.rac_textSignal,
self.passwordTextField.rac_textSignal,
RACObserve(LoginManager.sharedManager, loggingIn),
RACObserve(self, loggedIn)
] reduce:^(NSString *username, NSString *password, NSNumber *loggingIn, NSNumber *loggedIn) {
return @(username.length > 0 && password.length > 0 && !loggingIn.boolValue && !loggedIn.boolValue);
}];