正如标题所说,在订阅RACSubet的RACSignal内的主题上调用sendNext什么都不做。什么都没有。我已经验证了第二个订阅者总是收到sendNext值,而不是在订阅内进行调用的那个。
代码:
设置
loginStateSubject = [RACSubject subject];
loginStateSignal = [loginStateSubject replayLast];
[loginStateSubject sendNext:[NSNumber numberWithInteger:LOGIN_IDLE]];
订阅者
[[loginStateSignal takeWhileBlock:^BOOL(NSNumber *state) {
if ([state intValue] == LOGGING_IN) {
NSLog(@"Login state is in LOGGING_IN. Complete subscriber.");
return false;
}
return true;
}] subscribeNext:^(NSNumber *state) {
if ([state intValue] == LOGIN_IDLE) {
NSLog(@"Login Idle. Attempt login.");
[loginStateSubject sendNext:[NSNumber numberWithInt:LOGGING_IN]];
[self loginWithParse];
} else {
NSLog(@"Log out in process while attempting to log in.");
}
}];
答案 0 :(得分:0)
我不想回答我自己的问题,但我找到了解决方案。由于某种原因,需要定义subscribeOn和observeOn。我假设他们会默认使用当前线程,在我的主线程中,但似乎他们需要特定的东西。
答案:
[[[[loginStateSignal
subscribeOn:[RACScheduler mainThreadScheduler]]
deliverOn:[RACScheduler mainThreadScheduler]]
takeWhileBlock:^BOOL(NSNumber *state) {
if ([state intValue] == LOGGING_IN) {
NSLog(@"Login state is in LOGGING_IN. Complete subscriber.");
return false;
}
return true;
}] subscribeNext:^(NSNumber *state) {
if ([state intValue] == LOGIN_IDLE) {
NSLog(@"Login Idle. Attempt login.");
[loginStateSubject sendNext:[NSNumber numberWithInt:LOGGING_IN]];
[self loginWithParse];
} else {
NSLog(@"Log out in process while attempting to log in.");
}
}];