Skip to content

Commit

Permalink
Merge pull request #138 from iShawnWang/master
Browse files Browse the repository at this point in the history
add prefix `fic` to all the property and method in protocol `FICEntity`.
  • Loading branch information
mallorypaine authored Sep 12, 2016
2 parents 417084e + 3e1af93 commit 678bd7e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
10 changes: 5 additions & 5 deletions FastImageCache/FastImageCache/FastImageCache/FICEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ typedef void (^FICEntityImageDrawingBlock)(CGContextRef context, CGSize contextS
@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;
@property (nonatomic, copy, readonly) NSString *fic_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;
@property (nonatomic, copy, readonly) NSString *fic_sourceImageUUID;

/**
Returns the source image URL associated with a specific format name.
Expand All @@ -52,7 +52,7 @@ typedef void (^FICEntityImageDrawingBlock)(CGContextRef context, CGSize contextS
@see FICImageFormat
@see [FICImageCacheDelegate imageCache:wantsSourceImageForEntity:withFormatName:completionBlock:]
*/
- (NSURL *)sourceImageURLWithFormatName:(NSString *)formatName;
- (NSURL *)fic_sourceImageURLWithFormatName:(NSString *)formatName;

/**
Returns the drawing block for a specific image and format name.
Expand All @@ -73,14 +73,14 @@ typedef void (^FICEntityImageDrawingBlock)(CGContextRef context, CGSize contextS
@note This block will always be called from the serial dispatch queue used by the image cache.
*/
- (FICEntityImageDrawingBlock)drawingBlockForImage:(UIImage *)image withFormatName:(NSString *)formatName;
- (FICEntityImageDrawingBlock)fic_drawingBlockForImage:(UIImage *)image withFormatName:(NSString *)formatName;

@optional
/**
Returns the image for a format
@param format The image format that identifies which image table is requesting the source image.
*/
- (UIImage *)imageForFormat:(FICImageFormat *)format;
- (UIImage *)fic_imageForFormat:(FICImageFormat *)format;

@end
36 changes: 18 additions & 18 deletions FastImageCache/FastImageCache/FastImageCache/FICImageCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ - (BOOL)_retrieveImageForEntity:(id <FICEntity>)entity withFormatName:(NSString
BOOL imageExists = NO;

FICImageTable *imageTable = [_imageTables objectForKey:formatName];
NSString *entityUUID = [entity UUID];
NSString *sourceImageUUID = [entity sourceImageUUID];
NSString *entityUUID = [entity fic_UUID];
NSString *sourceImageUUID = [entity fic_sourceImageUUID];

if (loadSynchronously == NO && [imageTable entryExistsForEntityUUID:entityUUID sourceImageUUID:sourceImageUUID]) {
imageExists = YES;
Expand Down Expand Up @@ -196,7 +196,7 @@ - (BOOL)_retrieveImageForEntity:(id <FICEntity>)entity withFormatName:(NSString

if (image == nil) {
// No image for this UUID exists in the image table. We'll need to ask the delegate to retrieve the source asset.
NSURL *sourceImageURL = [entity sourceImageURLWithFormatName:formatName];
NSURL *sourceImageURL = [entity fic_sourceImageURLWithFormatName:formatName];

if (sourceImageURL != nil) {
// We check to see if this image is already being fetched.
Expand All @@ -216,9 +216,9 @@ - (BOOL)_retrieveImageForEntity:(id <FICEntity>)entity withFormatName:(NSString
if (needsToFetch) {
@autoreleasepool {
UIImage *image;
if ([entity respondsToSelector:@selector(imageForFormat:)]){
if ([entity respondsToSelector:@selector(fic_imageForFormat:)]){
FICImageFormat *format = [self formatWithName:formatName];
image = [entity imageForFormat:format];
image = [entity fic_imageForFormat:format];
}

if (image){
Expand Down Expand Up @@ -274,7 +274,7 @@ - (void)_imageDidLoad:(UIImage *)image forURL:(NSURL *)URL {
}

static void _FICAddCompletionBlockForEntity(NSString *formatName, NSMutableDictionary *entityRequestsDictionary, id <FICEntity> entity, FICImageCacheCompletionBlock completionBlock) {
NSString *entityUUID = [entity UUID];
NSString *entityUUID = [entity fic_UUID];
NSMutableDictionary *requestDictionary = [entityRequestsDictionary objectForKey:entityUUID];
NSMutableDictionary *completionBlocks = nil;

Expand Down Expand Up @@ -315,7 +315,7 @@ - (void)setImage:(UIImage *)image forEntity:(id <FICEntity>)entity withFormatNam
completionBlocksDictionary = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:[completionBlock copy]] forKey:formatName];
}

NSString *entityUUID = [entity UUID];
NSString *entityUUID = [entity fic_UUID];
FICImageTable *imageTable = [_imageTables objectForKey:formatName];
if (imageTable) {
[imageTable deleteEntryForEntityUUID:entityUUID];
Expand All @@ -338,21 +338,21 @@ - (void)_processImage:(UIImage *)image forEntity:(id <FICEntity>)entity completi

- (void)_processImage:(UIImage *)image forEntity:(id <FICEntity>)entity imageTable:(FICImageTable *)imageTable completionBlocks:(NSArray *)completionBlocks {
if (imageTable != nil) {
if ([entity UUID] == nil) {
if ([entity fic_UUID] == nil) {
[self _logMessage:[NSString stringWithFormat:@"*** FIC Error: %s entity %@ is missing its UUID.", __PRETTY_FUNCTION__, entity]];
return;
}

if ([entity sourceImageUUID] == nil) {
if ([entity fic_sourceImageUUID] == nil) {
[self _logMessage:[NSString stringWithFormat:@"*** FIC Error: %s entity %@ is missing its source image UUID.", __PRETTY_FUNCTION__, entity]];
return;
}

NSString *entityUUID = [entity UUID];
NSString *sourceImageUUID = [entity sourceImageUUID];
NSString *entityUUID = [entity fic_UUID];
NSString *sourceImageUUID = [entity fic_sourceImageUUID];
FICImageFormat *imageFormat = [imageTable imageFormat];
NSString *imageFormatName = [imageFormat name];
FICEntityImageDrawingBlock imageDrawingBlock = [entity drawingBlockForImage:image withFormatName:imageFormatName];
FICEntityImageDrawingBlock imageDrawingBlock = [entity fic_drawingBlockForImage:image withFormatName:imageFormatName];

dispatch_async([FICImageCache dispatchQueue], ^{
[imageTable setEntryForEntityUUID:entityUUID sourceImageUUID:sourceImageUUID imageDrawingBlock:imageDrawingBlock];
Expand Down Expand Up @@ -412,7 +412,7 @@ - (NSSet *)formatsToProcessForCompletionBlocks:(NSDictionary *)completionBlocksD
}

// If the image already exists, keep going
if ([table entryExistsForEntityUUID:entity.UUID sourceImageUUID:entity.sourceImageUUID]) {
if ([table entryExistsForEntityUUID:entity.fic_UUID sourceImageUUID:entity.fic_sourceImageUUID]) {
continue;
}

Expand All @@ -427,8 +427,8 @@ - (NSSet *)formatsToProcessForCompletionBlocks:(NSDictionary *)completionBlocksD

- (BOOL)imageExistsForEntity:(id <FICEntity>)entity withFormatName:(NSString *)formatName {
FICImageTable *imageTable = [_imageTables objectForKey:formatName];
NSString *entityUUID = [entity UUID];
NSString *sourceImageUUID = [entity sourceImageUUID];
NSString *entityUUID = [entity fic_UUID];
NSString *sourceImageUUID = [entity fic_sourceImageUUID];

BOOL imageExists = [imageTable entryExistsForEntityUUID:entityUUID sourceImageUUID:sourceImageUUID];

Expand All @@ -439,13 +439,13 @@ - (BOOL)imageExistsForEntity:(id <FICEntity>)entity withFormatName:(NSString *)f

- (void)deleteImageForEntity:(id <FICEntity>)entity withFormatName:(NSString *)formatName {
FICImageTable *imageTable = [_imageTables objectForKey:formatName];
NSString *entityUUID = [entity UUID];
NSString *entityUUID = [entity fic_UUID];
[imageTable deleteEntryForEntityUUID:entityUUID];
}

- (void)cancelImageRetrievalForEntity:(id <FICEntity>)entity withFormatName:(NSString *)formatName {
NSURL *sourceImageURL = [entity sourceImageURLWithFormatName:formatName];
NSString *entityUUID = [entity UUID];
NSURL *sourceImageURL = [entity fic_sourceImageURLWithFormatName:formatName];
NSString *entityUUID = [entity fic_UUID];

BOOL cancelImageLoadingForEntity = NO;
@synchronized (_requests) {
Expand Down
10 changes: 5 additions & 5 deletions FastImageCache/FastImageCacheDemo/Classes/FICDPhoto.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ - (void)deleteThumbnail {

#pragma mark - FICImageCacheEntity

- (NSString *)UUID {
- (NSString *)fic_UUID {
if (_UUID == nil) {
// MD5 hashing is expensive enough that we only want to do it once
NSString *imageName = [_sourceImageURL lastPathComponent];
Expand All @@ -178,15 +178,15 @@ - (NSString *)UUID {
return _UUID;
}

- (NSString *)sourceImageUUID {
return [self UUID];
- (NSString *)fic_sourceImageUUID {
return [self fic_UUID];
}

- (NSURL *)sourceImageURLWithFormatName:(NSString *)formatName {
- (NSURL *)fic_sourceImageURLWithFormatName:(NSString *)formatName {
return _sourceImageURL;
}

- (FICEntityImageDrawingBlock)drawingBlockForImage:(UIImage *)image withFormatName:(NSString *)formatName {
- (FICEntityImageDrawingBlock)fic_drawingBlockForImage:(UIImage *)image withFormatName:(NSString *)formatName {
FICEntityImageDrawingBlock drawingBlock = ^(CGContextRef contextRef, CGSize contextSize) {
CGRect contextBounds = CGRectZero;
contextBounds.size = contextSize;
Expand Down

0 comments on commit 678bd7e

Please sign in to comment.