Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove observer using ReactiveCocoa?

How to stop receiving new name after some event?

[RACObserve(self, username) subscribeNext:^(NSString *newName) {
    if ([newName isEqualToString:@"SomeString"])
    {
       //Do not observe any more
    }
}];

P.S. Sorry for obvious question, but I can't find answer

like image 807
serj Avatar asked Apr 15 '15 17:04

serj


1 Answers

You can use method 'dispose' of RACDisposable object which be returned from 'subscribeNext'.

__block RACDisposable *handler = [RACObserve(self, username) subscribeNext:^(NSString *newName) {
    if ([newName isEqualToString:@"SomeString"]) {
        //Do not observe any more
        [handler dispose]
    }
}];
like image 70
KM Gorbunov Avatar answered Oct 13 '22 12:10

KM Gorbunov