In ReactiveCocoa, itโs important to think a little about things: you donโt want to โremoveโ the observer, you want to create a signal that ends when something happens.
You can use takeUntilBlock: to receive a signal that stops sending values โโafter a certain time:
[[RACObserve(self, username) takeUntilBlock:^(NSString *name) { return [name isEqualToString:@"something"]; }] subscribeNext:^(NSString *name) { NSLog(@"%@", name); }];
But this will not send the next line @"something" , but only the names before it. If necessary, you can add it:
NSString *sentinel = @"something"; [[[RACObserve(self, username) takeUntilBlock:^(NSString *name) { return [name isEqualToString:sentinel]; }] concat:[RACSignal return:sentinel]] subscribeNext:^(NSString *name) { NSLog(@"%@", name); }];
It's not very elegant, but you could make a takeUntilBlockInclusive to help you with this and hide the rudeness there.
source share