I have the following code that runs through a series of image records, tries to find a record that's marked "primary", loads it, and assigns it to a UIImageView
:
// 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
[[[[[[self modelImagesSignal] 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
}]
// Catch errors
catch:^RACSignal *(NSError *error)
{
FLASH_REPORT_T(error.description, nil, xkFlashMessageTypeError) ;
return [RACSignal empty] ;
}] ;
- If there is no primary, I'd like to return the first record encountered, whether it's primary or not, and
- If there aren't any records encountered at all, I'd like to return a default image.
How can I do these?