This works as expected:
// 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 ;
}] ;
This does not; the image is never set:
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] ;
Why?
Here is the version that works:
Note that
AsyncImageFetcher'simageAtURL:cache:returns a signal.A few notes about this solution:
First I had to create a new private property
self.imageViewthat does nothing but returnself.headerView. The reason for this relates to the arguments that theRAC()macro can accept. I became suspicious that the parameters I was passing toRAC()was causing my problem, so I simplified it by doing the cast in the aforementioned private property:Then I tried:
But this didn't work. I then tried
This worked! So then I thought, let's get rid of
self.imageViewand see if it works with the casting right in the macro:Unfortunately, this yields a syntax error.
So, the solution that utilizes the casting private property works, but it feels like a workaround. I'm accepting the answer since it works for me, but I'd still like to know if there's a way I can do this without creating the (redundant) imageView property.