Skip to content

Instantly share code, notes, and snippets.

@DTHENG
Last active August 29, 2015 14:17
Show Gist options
  • Save DTHENG/de47b9e722861ec9644e to your computer and use it in GitHub Desktop.
Save DTHENG/de47b9e722861ec9644e to your computer and use it in GitHub Desktop.
DTObservable Example
#import <DTObservable/DTObservable.h>
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
DTObservable *exampleObservable = [[DTObservable alloc] init:^(DTSubscriber *subscriber) {
NSDictionary *profile = @{
@"firstName": @"Daniel",
@"lastName": @"Thengvall",
@"age": @25};
// Lets pretend something cpu intensive happens here
[NSThread sleepForTimeInterval:1.f];
[subscriber complete:profile];
}];
// if you want to run on a new thread
//[exampleObservable newThread];
[exampleObservable subscribe:[[DTSubscriber alloc] init:^(NSDictionary *profile) {
BOOL twentyFive = [profile[@"age"] intValue] == 25;
NSLog(@"Is age 25? %@", twentyFive ? @"YES" : @"NO");
} onError:^(NSError *error) {
NSLog(@"%@", error);
}]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment