Last active
July 14, 2017 04:05
-
-
Save SunXiaoShan/df5f36f15957656eef965a18f9d8cb2c to your computer and use it in GitHub Desktop.
RACSignalDemoFunction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (RACSignal *)RACSignalDemoFunction { | |
| return [RACSignal createSignal:^(id<RACSubscriber> subscriber) { | |
| // your code ... | |
| BOOL isSuccess = YES; | |
| NSObject *result = [NSObject new]; | |
| if (isSuccess) { | |
| [subscriber sendNext:result]; | |
| [subscriber sendCompleted]; | |
| } else { | |
| [subscriber sendError:[NSError new]]; | |
| } | |
| return [RACDisposable disposableWithBlock:^{ | |
| //TODO: | |
| }]; | |
| }]; | |
| } | |
| // example 1 | |
| RACSignal *singnal = [self RACSignalDemoFunction]; | |
| [singnal subscribeNext:^(id _Nullable x) { | |
| //TODO: your code | |
| } error:^(NSError * _Nullable error) { | |
| //TODO: your code | |
| }]; | |
| // example 2 | |
| [[self RACSignalDemoFunction] subscribeNext:^(id _Nullable x) { | |
| //TODO: next | |
| } error:^(NSError * _Nullable error) { | |
| //TODO: error | |
| } completed:^{ | |
| //TODO: completed | |
| }]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment