Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a ReactiveCocoa subscriber that receives a signal only once, then unsubscribes/releases itself?

I'm currently registering a subscriber to a property signal like this:

[RACAble(self.test) subscribeNext:^(id x) {
        NSLog(@"signal fired!");
 }];

The default functionality is that it fires every single time self.test is changed, but I just want it to fire once, and then unsubscribe. Is there a "once" argument or modifier I can pass to RAC when I create this subscriber?

like image 674
zakdances Avatar asked Mar 25 '13 12:03

zakdances


1 Answers

[[RACAble(self.test) take:1] subscribeNext:^(id x) {
    NSLog(@"signal fired!");
}];
like image 147
Josh Vera Avatar answered Nov 01 '22 13:11

Josh Vera