Advertisement
Guest User

Untitled

a guest
Apr 20th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. // Return a sequence for photos
  2. [[[[[[RACObserve(self, event.photos) filter:^BOOL(id value) { return value != nil ; }] flattenMap:^RACStream *(NSDictionary *photos)
  3. {
  4. NSLog(@"Got photos: %@" , photos) ;
  5. return photos.rac_sequence.signal ;
  6. }]
  7.  
  8. // Consider each photo
  9. filter:^BOOL(NSDictionary *photoDescriptor)
  10. {
  11. NSLog(@"Descriptor: %@" , photoDescriptor) ;
  12. return ((NSNumber *)photoDescriptor[@"primary"]).boolValue ;
  13. }]
  14.  
  15. // Load the selected photo
  16. map:^id(NSDictionary *selectedPhotoDescriptor)
  17. {
  18. NSLog(@"Photo URL: %@" , selectedPhotoDescriptor[@"url"]) ;
  19. return [[AsyncImageFetcher imageAtURL:[NSURL URLWithString:selectedPhotoDescriptor[@"url"]] cache:YES] firstOrDefault:[UIImage imageNamed:@"detail_placeholder"]] ;
  20. }]
  21.  
  22. // Deliver on main thread
  23. deliverOn:RACScheduler.mainThreadScheduler]
  24.  
  25. subscribeNext:^(id x)
  26. {
  27. ((UIImageView *)self.headerView).image = x ;
  28. }] ;
  29.  
  30. RAC( ((UIImageView *)self.headerView), image ) =
  31.  
  32. // Return a sequence for photos
  33. [[[[[RACObserve(self, event.photos) filter:^BOOL(id value) { return value != nil ; }] flattenMap:^RACStream *(NSDictionary *photos)
  34. {
  35. NSLog(@"Got photos: %@" , photos) ;
  36. return photos.rac_sequence.signal ;
  37. }]
  38.  
  39. // Consider each photo
  40. filter:^BOOL(NSDictionary *photoDescriptor)
  41. {
  42. NSLog(@"Descriptor: %@" , photoDescriptor) ;
  43. return ((NSNumber *)photoDescriptor[@"primary"]).boolValue ;
  44. }]
  45.  
  46. // Load the selected photo
  47. map:^id(NSDictionary *selectedPhotoDescriptor)
  48. {
  49. NSLog(@"Photo URL: %@" , selectedPhotoDescriptor[@"url"]) ;
  50. return [[AsyncImageFetcher imageAtURL:[NSURL URLWithString:selectedPhotoDescriptor[@"url"]] cache:YES] firstOrDefault:[UIImage imageNamed:@"detail_placeholder"]] ;
  51. }]
  52.  
  53. // Deliver on main thread
  54. deliverOn:RACScheduler.mainThreadScheduler] ;
  55.  
  56. // When there's a new image, fetch it, and set the headerView (which by default is an UIImageView)
  57. RAC( self, imageView.image ) =
  58.  
  59. // Return a sequence for photos
  60. [[[[RACObserve(self, event.photos) ignore:nil] flattenMap:^RACStream *(NSDictionary *photos)
  61. {
  62. NSLog(@"Got photos: %@" , photos) ;
  63. return photos.rac_sequence.signal ;
  64. }]
  65.  
  66. // Consider each photo
  67. filter:^BOOL(NSDictionary *photoDescriptor)
  68. {
  69. NSLog(@"Descriptor: %@" , photoDescriptor) ;
  70. return ((NSNumber *)photoDescriptor[@"primary"]).boolValue ;
  71. }]
  72.  
  73. // Load the selected photo
  74. flattenMap:^RACStream *(NSDictionary *selectedPhotoDescriptor)
  75. {
  76. NSLog(@"selected photo desc: %@" , selectedPhotoDescriptor) ;
  77. return [AsyncImageFetcher imageAtURL:[NSURL URLWithString:selectedPhotoDescriptor[@"url"]] cache:YES] ; // This will -deliverOn: the main thread
  78. }] ;
  79.  
  80. @synthesize imageView ;
  81. - (UIImageView *) imageView
  82. {
  83. return (id) self.headerView ;
  84. }
  85.  
  86. RAC( self.imageView, image ) = …
  87.  
  88. RAC( self, imageView.image ) = …
  89.  
  90. RAC( self, (((UIImageView *)headerView).image) ) = …
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement