简体   繁体   中英

'if / else' construction in Reactive Cocoa

I want to create if/else construction by Reactive Cocoa. I have the code : 在此处输入图片说明

In that construction called rac_testYES signal, but it's something strange because if:[RACSignal return:@0] return NO . Why call rac_testYES method?

This code works as expected. If you change the if statement to [RACSignal return:@1] then YES will be printed.

EDITED

The both methods are called because they are just a parameters for [RACSignal if:then:else:] method.

ReactivCocoa will call subscribeNext/subscribeComplited for the provided signal according to if if signal return YES or NO .

So if you wan do sth for YES:

-(RACSignal)rac_testYES {
    return [RACSignal createSignal:^RACDisposable *(id <RACSubscriber> subscriber) {
        //do sth
        [subscriber sendNext:@"YES"];
        [subscriber sendComplited]; 
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM