Skip to content

Instantly share code, notes, and snippets.

@SunXiaoShan
Last active July 14, 2017 04:05
Show Gist options
  • Select an option

  • Save SunXiaoShan/df5f36f15957656eef965a18f9d8cb2c to your computer and use it in GitHub Desktop.

Select an option

Save SunXiaoShan/df5f36f15957656eef965a18f9d8cb2c to your computer and use it in GitHub Desktop.
RACSignalDemoFunction
- (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