The basics of Reactive Cocoa. The tips and tricks in this presentation will cover almost all the use cases for Reactive Cocoa. Demo here: https://github.com/rob-brown/Demos/tree/master/RACDemo.
20. Tips and Tricks
Transform the values of a signal:
[signal map:^id(NSString * text) {
return [text uppercaseString];
}];
21. Tips and Tricks
Combine the results of many signals:
[RACSignal combineLatest:@[s1, s2] reduce:
^id(NSNumber * b1, NSNumber * b2) {
return @([b1 boolValue] &&
[b2 boolValue]);
}];
22. Tips and Tricks
Watch for when multiple tasks complete:
[[RACSignal merge:@[signal1, signal2]
subscribeCompleted:^{
NSLog(@“All done”);
}];
23. Tips and Tricks
Add actions to buttons:
self.button.rac_command =
[[RACCommand alloc]
initWithSignalBlock:^RACSignal *(id x) {
// Code goes here
};
24. Tips and Tricks
Create arbitrary signals:
[RACSignal createSignal:
^RACDisposable *(id<RACSubscriber> subscriber)
{
// Send next, error, and completed
// messages to subscriber
}];
25. Tips and Tricks
Deliver signal results to the main thread:
[backgroundSignal deliverOn:
[RACScheduler mainThreadScheduler]];
26. Tips and Tricks
If you need to perform side effects:
[signal doNext:^(id value) {…}];
[signal doError:^(NSError * error) {…}];
[signal doCompleted:^{…}];