Last active
August 29, 2015 14:17
-
-
Save DTHENG/de47b9e722861ec9644e to your computer and use it in GitHub Desktop.
DTObservable Example
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
#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