Reputation: 469
I'm using ReactiveCocoa 2.5 because I need to support iOS 7. I'm new at ReactiveCocoa. I've write this code:
__weak typeof(self) weakSelf = self;
[RACObserve(_currentUser, username) subscribeNext:^(NSString *newUsername) {
[weakSelf performSelector:@selector(saveUserChanges) withObject:nil afterDelay:.1];
}];
And subscribeNext
block get called instantly. _currentUser
's username
property not changed after I call RACObserve subscribeNext
. Maybe it's normal behaviour and subscribeNext
should get called first time after starting to observe? If it's normal how can I avoid this?
Upvotes: 0
Views: 810
Reputation: 22433
Yes, this is normal -- signals created via RACObserve
will always send their initial values immediately. If you only want subsequent values, you can skip the initial value like so:
[[RACObserve(_currentUser, username) skip:1] subscribeNext:^(NSString *newUserName) {
[weakSelf performSelector:@selector(saveUserChanges) withObject:nil afterDelay:.1];
}];
Upvotes: 4