It's important to think about things a little differently in ReactiveCocoa: you don't want to "remove" an observer, you want to create a signal that completes when something happens.
You can use takeUntilBlock:
to derive a signal that will stop sending values after a certain time:
[[RACObserve(self, username) takeUntilBlock:^(NSString *name) {
return [name isEqualToString:@"something"];
}] subscribeNext:^(NSString *name) {
NSLog(@"%@", name);
}];
But that will not send a next for the string @"something"
, only the names before it. If that's desired, you could append 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
helper that would get you this behavior, and hide the grossness in there.