tagirkaZ
tagirkaZ

Reputation: 469

RACObserve subscribeNext performSelector:afterDelay: not called

I'm using ReactiveCocoa 2.5 because I need to support iOS 7. I'm new at ReactiveCocoa. I have this code:

   __weak typeof(self) weakSelf = self;
   [RACObserve(_currentUser, username) subscribeNext:^(NSString *newUsername) {
        [weakSelf performSelector:@selector(saveUserChanges) withObject:nil afterDelay:.1];
   }];

First time when code reaches performSelector everything works just fine and saveUserChanges method get called after delay. But then the code reaches the same performSelector line many times but saveUserChanges method never get called again. What is wrong with my code?

Upvotes: 0

Views: 277

Answers (1)

Harrison Xi
Harrison Xi

Reputation: 796

Maybe your weakSelf was released. Make sure the weakSelf is not nil in the block.

When you use weak object in block, it's better to strong it again like this:

@weakify(self);
[RACObserve(_currentUser, username) subscribeNext:^(NSString *newUsername) {
    @strongify(self);
    [self performSelector:@selector(saveUserChanges) withObject:nil afterDelay:.1];
}];

Upvotes: 1

Related Questions