Slide 40
Slide 40 text
// ImageViewModel.h
@interface ImageViewModel : ViewModel
/// The latest image downloaded from imageURL. May be nil.
@property (nonatomic, readonly) UIImage *image;
/// The progress of the current download.
@property (nonatomic, readonly) CGFloat progress;
/// ErrorViewModel encapsulates any download error.
@property (nonatomic, readonly) BOOL hasError;
@property (nonatomic, readonly) ErrorViewModel *errorViewModel;
/// Whether any download operation is in progress.
@property (nonatomic, readonly, getter=isLoading) BOOL loading;
/// The View layer should call this block when a user taps the image view.
/// If an image exists and there is no error, it will call `openImageURLBlock`.
/// If an error exists, it will try to fetch the image again.
@property (nonatomic, readonly) void (^selectBlock)(void);
/// Exists on ViewModel superclass.
/// Setting active to YES triggers the image load unless the image
/// has already been fetched.
@property (nonatomic, getter=isActive) BOOL active;
@property (nonatomic, readonly) NSURL *imageURL;
- (instancetype)initWithImageURL:(NSURL *)imageURL openImageURLBlock:(void (^)
(NSURL *))openImageURLBlock imageController:(ImageController *)imageController;