Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With ReactiveCocoa bind to inverse of BOOL

I would like to do the opposite of the following code:

RAC(self.activityIndicator, hidden) = RACObserve(self.playButton, selected);

When the play button is selected the activity indicator should be NOT hidden.

What is the best way to do this using ReactiveCocoa?

like image 332
Onato Avatar asked Jan 25 '14 18:01

Onato


2 Answers

There's a signal operator for this, -not.

RAC(self.activityIndicator, hidden) = [RACObserve(self.playButton, selected) not];
like image 116
Dave Lee Avatar answered Oct 22 '22 12:10

Dave Lee


map: is what you need.

RAC(self.activityIndicator, hidden) = [RACObserve(self.playButton, selected) map:^id(id value) {
    return @(![value boolValue]);
}];

This transforms the signal into another one based on what you return from the map function.

like image 4
Lance Avatar answered Oct 22 '22 10:10

Lance