Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Return a sequence for photos
- [[[[[[RACObserve(self, event.photos) filter:^BOOL(id value) { return value != nil ; }] flattenMap:^RACStream *(NSDictionary *photos)
- {
- NSLog(@"Got photos: %@" , photos) ;
- return photos.rac_sequence.signal ;
- }]
- // Consider each photo
- filter:^BOOL(NSDictionary *photoDescriptor)
- {
- NSLog(@"Descriptor: %@" , photoDescriptor) ;
- return ((NSNumber *)photoDescriptor[@"primary"]).boolValue ;
- }]
- // Load the selected photo
- map:^id(NSDictionary *selectedPhotoDescriptor)
- {
- NSLog(@"Photo URL: %@" , selectedPhotoDescriptor[@"url"]) ;
- return [[AsyncImageFetcher imageAtURL:[NSURL URLWithString:selectedPhotoDescriptor[@"url"]] cache:YES] firstOrDefault:[UIImage imageNamed:@"detail_placeholder"]] ;
- }]
- // Deliver on main thread
- deliverOn:RACScheduler.mainThreadScheduler]
- subscribeNext:^(id x)
- {
- ((UIImageView *)self.headerView).image = x ;
- }] ;
- RAC( ((UIImageView *)self.headerView), image ) =
- // Return a sequence for photos
- [[[[[RACObserve(self, event.photos) filter:^BOOL(id value) { return value != nil ; }] flattenMap:^RACStream *(NSDictionary *photos)
- {
- NSLog(@"Got photos: %@" , photos) ;
- return photos.rac_sequence.signal ;
- }]
- // Consider each photo
- filter:^BOOL(NSDictionary *photoDescriptor)
- {
- NSLog(@"Descriptor: %@" , photoDescriptor) ;
- return ((NSNumber *)photoDescriptor[@"primary"]).boolValue ;
- }]
- // Load the selected photo
- map:^id(NSDictionary *selectedPhotoDescriptor)
- {
- NSLog(@"Photo URL: %@" , selectedPhotoDescriptor[@"url"]) ;
- return [[AsyncImageFetcher imageAtURL:[NSURL URLWithString:selectedPhotoDescriptor[@"url"]] cache:YES] firstOrDefault:[UIImage imageNamed:@"detail_placeholder"]] ;
- }]
- // Deliver on main thread
- deliverOn:RACScheduler.mainThreadScheduler] ;
- // When there's a new image, fetch it, and set the headerView (which by default is an UIImageView)
- RAC( self, imageView.image ) =
- // Return a sequence for photos
- [[[[RACObserve(self, event.photos) ignore:nil] flattenMap:^RACStream *(NSDictionary *photos)
- {
- NSLog(@"Got photos: %@" , photos) ;
- return photos.rac_sequence.signal ;
- }]
- // Consider each photo
- filter:^BOOL(NSDictionary *photoDescriptor)
- {
- NSLog(@"Descriptor: %@" , photoDescriptor) ;
- return ((NSNumber *)photoDescriptor[@"primary"]).boolValue ;
- }]
- // Load the selected photo
- flattenMap:^RACStream *(NSDictionary *selectedPhotoDescriptor)
- {
- NSLog(@"selected photo desc: %@" , selectedPhotoDescriptor) ;
- return [AsyncImageFetcher imageAtURL:[NSURL URLWithString:selectedPhotoDescriptor[@"url"]] cache:YES] ; // This will -deliverOn: the main thread
- }] ;
- @synthesize imageView ;
- - (UIImageView *) imageView
- {
- return (id) self.headerView ;
- }
- RAC( self.imageView, image ) = …
- RAC( self, imageView.image ) = …
- RAC( self, (((UIImageView *)headerView).image) ) = …
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement