Skip to content

Commit 7cf6b35

Browse files
committed
Merge remote-tracking branch 'path/master'
fix conflicts
2 parents 55fcf55 + 0b00b01 commit 7cf6b35

File tree

8 files changed

+72
-76
lines changed

8 files changed

+72
-76
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ profile
1919
DerivedData
2020

2121
# Demo Images
22-
FastImageCacheDemo/Demo Images/*.jpg
22+
FastImageCache/FastImageCacheDemo/Demo Images/*.jpg
2323
Carthage

FastImageCache/FastImageCache.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@
528528
B2E5677F1B316D5800906840 /* Debug */ = {
529529
isa = XCBuildConfiguration;
530530
buildSettings = {
531+
APPLICATION_EXTENSION_API_ONLY = YES;
531532
DEFINES_MODULE = YES;
532533
DYLIB_COMPATIBILITY_VERSION = 1;
533534
DYLIB_CURRENT_VERSION = 1;
@@ -544,6 +545,7 @@
544545
B2E567801B316D5800906840 /* Release */ = {
545546
isa = XCBuildConfiguration;
546547
buildSettings = {
548+
APPLICATION_EXTENSION_API_ONLY = YES;
547549
DEFINES_MODULE = YES;
548550
DYLIB_COMPATIBILITY_VERSION = 1;
549551
DYLIB_CURRENT_VERSION = 1;

FastImageCache/FastImageCache/FastImageCache/FICEntity.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ typedef void (^FICEntityImageDrawingBlock)(CGContextRef context, CGSize contextS
2626
@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
2727
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.
2828
*/
29-
@property (nonatomic, copy, readonly) NSString *UUID;
29+
@property (nonatomic, copy, readonly) NSString *fic_UUID;
3030

3131
/**
3232
A string that uniquely identifies an entity's source image.
3333
3434
@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
3535
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).
3636
*/
37-
@property (nonatomic, copy, readonly) NSString *sourceImageUUID;
37+
@property (nonatomic, copy, readonly) NSString *fic_sourceImageUUID;
3838

3939
/**
4040
Returns the source image URL associated with a specific format name.
@@ -54,7 +54,8 @@ typedef void (^FICEntityImageDrawingBlock)(CGContextRef context, CGSize contextS
5454
@see FICImageFormat
5555
@see [FICImageCacheDelegate imageCache:wantsSourceImageForEntity:withFormatName:completionBlock:]
5656
*/
57-
- (nullable NSURL *)sourceImageURLWithFormatName:(NSString *)formatName;
57+
- (nullable NSURL *)fic_sourceImageURLWithFormatName:(NSString *)formatName;
58+
5859

5960
/**
6061
Returns the drawing block for a specific image and format name.
@@ -75,15 +76,15 @@ typedef void (^FICEntityImageDrawingBlock)(CGContextRef context, CGSize contextS
7576
7677
@note This block will always be called from the serial dispatch queue used by the image cache.
7778
*/
78-
- (nullable FICEntityImageDrawingBlock)drawingBlockForImage:(UIImage *)image withFormatName:(NSString *)formatName;
79+
- (nullable FICEntityImageDrawingBlock)fic_drawingBlockForImage:(UIImage *)image withFormatName:(NSString *)formatName;
7980

8081
@optional
8182
/**
8283
Returns the image for a format
8384
8485
@param format The image format that identifies which image table is requesting the source image.
8586
*/
86-
- (nullable UIImage *)imageForFormat:(FICImageFormat *)format;
87+
- (nullable UIImage *)fic_imageForFormat:(FICImageFormat *)format;
8788

8889
@end
8990

FastImageCache/FastImageCache/FastImageCache/FICImageCache.m

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ - (BOOL)_retrieveImageForEntity:(id <FICEntity>)entity withFormatName:(NSString
163163
BOOL imageExists = NO;
164164

165165
FICImageTable *imageTable = [_imageTables objectForKey:formatName];
166-
NSString *entityUUID = [entity UUID];
167-
NSString *sourceImageUUID = [entity sourceImageUUID];
166+
NSString *entityUUID = [entity fic_UUID];
167+
NSString *sourceImageUUID = [entity fic_sourceImageUUID];
168168

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

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

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

224224
if (image){
@@ -274,7 +274,7 @@ - (void)_imageDidLoad:(UIImage *)image forURL:(NSURL *)URL {
274274
}
275275

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

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

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

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

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

351-
NSString *entityUUID = [entity UUID];
352-
NSString *sourceImageUUID = [entity sourceImageUUID];
351+
NSString *entityUUID = [entity fic_UUID];
352+
NSString *sourceImageUUID = [entity fic_sourceImageUUID];
353353
FICImageFormat *imageFormat = [imageTable imageFormat];
354354
NSString *imageFormatName = [imageFormat name];
355-
FICEntityImageDrawingBlock imageDrawingBlock = [entity drawingBlockForImage:image withFormatName:imageFormatName];
355+
FICEntityImageDrawingBlock imageDrawingBlock = [entity fic_drawingBlockForImage:image withFormatName:imageFormatName];
356356

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

414414
// If the image already exists, keep going
415-
if ([table entryExistsForEntityUUID:entity.UUID sourceImageUUID:entity.sourceImageUUID]) {
415+
if ([table entryExistsForEntityUUID:entity.fic_UUID sourceImageUUID:entity.fic_sourceImageUUID]) {
416416
continue;
417417
}
418418

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

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

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

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

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

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

450450
BOOL cancelImageLoadingForEntity = NO;
451451
@synchronized (_requests) {

FastImageCache/FastImageCacheDemo/Classes/FICDPhoto.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ - (void)deleteThumbnail {
167167

168168
#pragma mark - FICImageCacheEntity
169169

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

181-
- (NSString *)sourceImageUUID {
182-
return [self UUID];
181+
- (NSString *)fic_sourceImageUUID {
182+
return [self fic_UUID];
183183
}
184184

185-
- (NSURL *)sourceImageURLWithFormatName:(NSString *)formatName {
185+
- (NSURL *)fic_sourceImageURLWithFormatName:(NSString *)formatName {
186186
return _sourceImageURL;
187187
}
188188

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

FastImageCache/FastImageCacheDemo/Classes/FICDPhotosTableViewCell.m

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ @interface FICDPhotosTableViewCell () <UIGestureRecognizerDelegate> {
1919
NSArray *_photos;
2020
NSString *_imageFormatName;
2121

22-
NSMutableArray *_imageViews;
22+
NSArray *_imageViews;
2323
UITapGestureRecognizer *_tapGestureRecognizer;
2424
}
2525

@@ -39,42 +39,28 @@ @implementation FICDPhotosTableViewCell
3939
- (void)setPhotos:(NSArray *)photos {
4040
if (photos != _photos) {
4141
_photos = [photos copy];
42-
43-
// Either create the image views for this cell or clear them out if they already exist
44-
if (_imageViews == nil) {
45-
NSInteger photosPerRow = [[self class] photosPerRow];
46-
_imageViews = [[NSMutableArray alloc] initWithCapacity:photosPerRow];
47-
48-
for (NSInteger i = 0; i < photosPerRow; i++) {
49-
UIImageView *imageView = [[UIImageView alloc] init];
50-
[imageView setContentMode:UIViewContentModeScaleAspectFill];
51-
[_imageViews addObject:imageView];
52-
}
53-
} else {
54-
for (UIImageView *imageView in _imageViews) {
55-
[imageView setImage:nil];
56-
[imageView removeFromSuperview];
57-
}
58-
}
59-
60-
NSInteger photosCount = [_photos count];
61-
for (NSInteger i = 0; i < photosCount; i++) {
62-
FICDPhoto *photo = [_photos objectAtIndex:i];
42+
43+
for (NSInteger i = 0; i < [_imageViews count]; i++) {
6344
UIImageView *imageView = [_imageViews objectAtIndex:i];
64-
65-
if (_usesImageTable) {
66-
[[FICImageCache sharedImageCache] retrieveImageForEntity:photo withFormatName:_imageFormatName completionBlock:^(id<FICEntity> entity, NSString *formatName, UIImage *image) {
67-
// This completion block may be called much later. We should check to make sure this cell hasn't been reused for different photos before displaying the image that has loaded.
68-
if (photos == [self photos]) {
69-
[imageView setImage:image];
70-
}
71-
}];
45+
46+
if (i < [_photos count]) {
47+
FICDPhoto *photo = [_photos objectAtIndex:i];
48+
49+
if (_usesImageTable) {
50+
[[FICImageCache sharedImageCache] retrieveImageForEntity:photo withFormatName:_imageFormatName completionBlock:^(id<FICEntity> entity, NSString *formatName, UIImage *image) {
51+
// This completion block may be called much later. We should check to make sure this cell hasn't been reused for different photos before displaying the image that has loaded.
52+
if (photos == [self photos]) {
53+
[imageView setImage:image];
54+
}
55+
}];
56+
} else {
57+
[imageView setImage:[photo thumbnailImage]];
58+
}
7259
} else {
73-
[imageView setImage:[photo thumbnailImage]];
60+
// Last row might not be full
61+
[imageView setImage:nil];
7462
}
7563
}
76-
77-
[self setNeedsLayout];
7864
}
7965
}
8066

@@ -117,6 +103,18 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
117103
if (self != nil) {
118104
_tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_tapGestureRecognizerStateDidChange)];
119105
[self addGestureRecognizer:_tapGestureRecognizer];
106+
107+
NSInteger photosPerRow = [[self class] photosPerRow];
108+
NSMutableArray *imageViews = [[NSMutableArray alloc] initWithCapacity:photosPerRow];
109+
110+
for (NSInteger i = 0; i < photosPerRow; i++) {
111+
UIImageView *imageView = [[UIImageView alloc] init];
112+
[imageView setContentMode:UIViewContentModeScaleAspectFill];
113+
[imageViews addObject:imageView];
114+
[self.contentView addSubview:imageView];
115+
}
116+
117+
_imageViews = [imageViews copy];
120118
}
121119

122120
return self;
@@ -139,14 +137,12 @@ - (void)layoutSubviews {
139137
CGFloat outerPadding = [[self class] outerPadding];
140138

141139
CGRect imageViewFrame = CGRectMake(outerPadding, outerPadding, FICDPhotoSquareImageSize.width, FICDPhotoSquareImageSize.height);
142-
143-
UIView *contentView = [self contentView];
140+
144141
NSInteger count = [_photos count];
145142

146143
for (NSInteger i = 0; i < count; i++) {
147144
UIImageView *imageView = [_imageViews objectAtIndex:i];
148145
[imageView setFrame:imageViewFrame];
149-
[contentView addSubview:imageView];
150146

151147
imageViewFrame.origin.x += imageViewFrame.size.width + innerPadding;
152148
}

FastImageCache/FastImageCacheDemo/Classes/FICDViewController.m

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ - (void)loadView {
9595
[_tableView setDelegate:self];
9696
[_tableView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
9797
[_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
98+
[_tableView registerClass:[FICDPhotosTableViewCell class] forCellReuseIdentifier:[FICDPhotosTableViewCell reuseIdentifier]];
9899

99100
CGFloat tableViewCellOuterPadding = [FICDPhotosTableViewCell outerPadding];
100101
[_tableView setContentInset:UIEdgeInsetsMake(0, 0, tableViewCellOuterPadding, 0)];
@@ -461,13 +462,9 @@ - (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)
461462
- (UITableViewCell*)tableView:(UITableView*)table cellForRowAtIndexPath:(NSIndexPath*)indexPath {
462463
NSString *reuseIdentifier = [FICDPhotosTableViewCell reuseIdentifier];
463464

464-
FICDPhotosTableViewCell *tableViewCell = (FICDPhotosTableViewCell *)[table dequeueReusableCellWithIdentifier:reuseIdentifier];
465-
if (tableViewCell == nil) {
466-
tableViewCell = [[FICDPhotosTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
467-
[tableViewCell setBackgroundColor:[table backgroundColor]];
468-
[tableViewCell setSelectionStyle:UITableViewCellSelectionStyleNone];
469-
}
470-
465+
FICDPhotosTableViewCell *tableViewCell = (FICDPhotosTableViewCell *)[table dequeueReusableCellWithIdentifier:reuseIdentifier forIndexPath:indexPath];
466+
tableViewCell.selectionStyle = UITableViewCellSeparatorStyleNone;
467+
471468
[tableViewCell setDelegate:self];
472469
[tableViewCell setImageFormatName:_imageFormatName];
473470

0 commit comments

Comments
 (0)