forked from path/FastImageCache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FICEntity.h
77 lines (54 loc) · 3.93 KB
/
FICEntity.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// FICEntity.h
// FastImageCache
//
// Copyright (c) 2013 Path, Inc.
// See LICENSE for full license agreement.
//
#import "FICImports.h"
typedef void (^FICEntityImageDrawingBlock)(CGContextRef context, CGSize contextSize);
/**
`FICEntity` is a protocol that classes interacting with the image cache must conform to. An entity uniquely identifies entries in image tables, which are instances of `<FICImageTable>`.
*/
@protocol FICEntity <NSObject>
@required
/**
A string that uniquely identifies this entity.
@discussion Within each image table, each entry is identified by an entity's UUID. Ideally, this value should never change for an entity. For example, if your entity class is a person
model, its UUID might be an API-assigned, unchanging, unique user ID. No matter how the properties of the person change, its user ID should never change.
*/
@property (nonatomic, copy, readonly) NSString *UUID;
/**
A string that uniquely identifies an entity's source image.
@discussion While `<UUID>` should be unchanging, a source image UUID might change. For example, if your entity class is a person model, its source image UUID might change every time the
person changes their profile photo. In this case, the source image UUID might be a hash of the profile photo URL (assuming each image is given a unique URL).
*/
@property (nonatomic, copy, readonly) NSString *sourceImageUUID;
/**
Returns the source image URL associated with a specific format name.
@param formatName The name of the image format that identifies which image table is requesting the source image.
@return A URL representing the requested source image.
@discussion Fast Image Cache operates on URLs when requesting source images. Typically, these URLs will point to remote image resources that must be downloaded from the Internet. While the
URL returned by this method must be a valid instance of `NSURL`, it does not need to point to an actual remote resource. The URL might point to a file path on disk or be composed of a custom
URL scheme of your choosing. The image cache's delegate is prompted to provide a source image for a particular entity and format name when it cannot find the requested image. It only uses the
URL returned by this method to key image cache requests. No network or file operations are performed by the image cache.
An example of when this method might return different source image URLs for the same entity is if you have defined several image formats for different thumbnail sizes and styles. For very
large thumbnails, the source image URL might be the original image. For smaller thumbnails, the source image URL might point to a downscaled version of the original image.
@see FICImageFormat
@see [FICImageCacheDelegate imageCache:wantsSourceImageForEntity:withFormatName:completionBlock:]
*/
- (NSURL *)sourceImageURLWithFormatName:(NSString *)formatName;
/**
Returns the drawing block for a specific image and format name.
@param image The cached image that represents this entity.
@param formatName The name of the image format that identifies which image table is requesting the source image.
@return The drawing block used to draw the image data to be stored in the image table.
The drawing block's type is defined as follows:
typedef void (^FICEntityImageDrawingBlock)(CGContextRef context, CGSize contextSize)
@discussion Each entity is responsible for drawing its own source image into the bitmap context provided by the image table that will store the image data. Often it is sufficient to simply
draw the image into the bitmap context. However, if you wish to apply any additional graphics processing to the source image before it is stored (such as clipping the image to a roundect rect),
you may use this block to do so.
@note This block will always be called from the serial dispatch queue used by the image cache.
*/
- (FICEntityImageDrawingBlock)drawingBlockForImage:(UIImage *)image withFormatName:(NSString *)formatName;
@end