Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilerwarnings #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 21 additions & 18 deletions Haneke/HNKCache.m
Expand Up @@ -131,19 +131,23 @@ - (BOOL)fetchImageForFetcher:(id<HNKFetcher>)fetcher formatName:(NSString *)form
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
HNKCacheFormat *format = _formats[formatName];

[self fetchImageFromFetcher:fetcher completionBlock:^(UIImage *originalImage, NSError *error) {
[self fetchImageFromFetcher:fetcher completionBlock:^(UIImage *originalImage, NSError *fetchError) {
if (!originalImage)
{
dispatch_async(dispatch_get_main_queue(), ^{
if (failureBlock) failureBlock(error);
if (failureBlock) {
failureBlock(fetchError);
}
});
return;
}

UIImage *image = [self imageFromOriginal:originalImage key:key format:format];
dispatch_async(dispatch_get_main_queue(), ^{
[self setMemoryImage:image forKey:key format:format];
if (successBlock) successBlock(image);
if (successBlock) {
successBlock(image);
}
});
[self setDiskImage:image forKey:key format:format];
}];
Expand All @@ -169,26 +173,26 @@ - (BOOL)fetchImageForKey:(NSString*)key formatName:(NSString *)formatName succes

[format.diskCache fetchDataForKey:key success:^(NSData *data) {
HanekeLog(@"Disk cache hit: %@/%@", formatName, key.lastPathComponent);
UIImage *image = [UIImage imageWithData:data];
if (image)
UIImage *imageFromDisk = [UIImage imageWithData:data];
if (imageFromDisk)
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIImage *decompressedImage = [image hnk_decompressedImage];
UIImage *decompressedImage = [imageFromDisk hnk_decompressedImage];
dispatch_async(dispatch_get_main_queue(), ^{
[self setMemoryImage:decompressedImage forKey:key format:format];
if (successBlock) successBlock(decompressedImage);
});
});
[self updateAccessDateOfImage:image key:key format:format];
[self updateAccessDateOfImage:imageFromDisk key:key format:format];
return;
}
else
{
NSString *errorDescription = [NSString stringWithFormat:NSLocalizedString(@"Disk cache: Cannot read image for key %@", @""), key.lastPathComponent];
HanekeLog(@"%@", errorDescription);
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey : errorDescription};
NSError *error = [NSError errorWithDomain:HNKErrorDomain code:HNKErrorDiskCacheCannotReadImageFromData userInfo:userInfo];
if (failureBlock) failureBlock(error);
}
if (failureBlock) {
failureBlock(error);
}
} failure:^(NSError *error) {
if (error.code == NSFileReadNoSuchFileError)
{
Expand Down Expand Up @@ -401,7 +405,7 @@ - (instancetype)initWithName:(NSString *)name
- (UIImage*)resizedImageFromImage:(UIImage*)originalImage
{
const CGSize formatSize = self.size;
CGSize resizedSize;
CGSize resizedSize = CGSizeZero;
switch (self.scaleMode) {
case HNKScaleModeAspectFill:
resizedSize = [originalImage hnk_aspectFillSizeForSize:formatSize];
Expand Down Expand Up @@ -468,7 +472,7 @@ - (CGSize)hnk_aspectFillSizeForSize:(CGSize)size
CGSize resultSize;
resultSize.width = self.size.width * scale;
resultSize.height = self.size.height * scale;
return CGSizeMake(ceil(resultSize.width), ceil(resultSize.height));
return CGSizeMake(ceilf(resultSize.width), ceilf(resultSize.height));
}

- (NSData*)hnk_dataWithCompressionQuality:(CGFloat)compressionQuality
Expand All @@ -491,7 +495,7 @@ - (CGSize)hnk_aspectFitSizeForSize:(CGSize)size
{
resultSize.height = size.width / sourceAspect;
}
return CGSizeMake(ceil(resultSize.width), ceil(resultSize.height));
return CGSizeMake(ceilf(resultSize.width), ceilf(resultSize.height));
}

- (UIImage *)hnk_decompressedImage;
Expand Down Expand Up @@ -520,10 +524,9 @@ - (UIImage *)hnk_decompressedImage;
case kCGImageAlphaOnly:
case kCGImageAlphaLast:
case kCGImageAlphaFirst:
{ // Unsupported
default:
// Unsupported
return self;
}
break;
}

const CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
Expand All @@ -545,7 +548,7 @@ - (UIImage *)hnk_decompressedImage;

// Flip coordinate system. See: http://stackoverflow.com/questions/506622/cgcontextdrawimage-draws-image-upside-down-when-passed-uiimage-cgimage
CGContextTranslateCTM(context, 0, pixelSize.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextScaleCTM(context, 1.0, -1.0f);

// UIImage and drawInRect takes into account image orientation, unlike CGContextDrawImage.
[self drawInRect:imageRect];
Expand Down
2 changes: 1 addition & 1 deletion Haneke/UIButton+Haneke.h
Expand Up @@ -111,7 +111,7 @@
@discussion If needed, the least recently used images in the cache will be evicted in background.
@warning If a success block is provided you will be responsible for setting the image.
*/
- (void)hnk_setImage:(UIImage*)image withKey:(NSString*)key forState:(UIControlState)state placeholder:(UIImage*)placeholder success:(void (^)(UIImage *image))successBlock failure:(void (^)(NSError *error))failureBlock;
- (void)hnk_setImage:(UIImage *)image withKey:(NSString *)key forState:(UIControlState)state placeholder:(UIImage *)placeholder success:(void (^)(UIImage *fetchedImage))successBlock failure:(void (^)(NSError *error))failureBlock;

/** Loads, resizes, displays and caches an appropiately sized foreground image from the given fetcher.
@param fetcher Fetcher from which the original image will be retrieved if needed. The fetcher will have to provide the original image only if it can't be found in the cache.
Expand Down
2 changes: 1 addition & 1 deletion Haneke/UIButton+Haneke.m
Expand Up @@ -71,7 +71,7 @@ - (void)hnk_setImage:(UIImage*)image withKey:(NSString*)key forState:(UIControlS
[self hnk_setImage:image withKey:key forState:state placeholder:placeholder success:nil failure:nil];
}

- (void)hnk_setImage:(UIImage*)image withKey:(NSString*)key forState:(UIControlState)state placeholder:(UIImage*)placeholder success:(void (^)(UIImage *image))successBlock failure:(void (^)(NSError *error))failureBlock
- (void)hnk_setImage:(UIImage *)image withKey:(NSString *)key forState:(UIControlState)state placeholder:(UIImage *)placeholder success:(void (^)(UIImage *fetchedImage))successBlock failure:(void (^)(NSError *error))failureBlock
{
id<HNKFetcher> fetcher = [[HNKSimpleFetcher alloc] initWithKey:key image:image];
[self hnk_setImageFromFetcher:fetcher forState:state placeholder:placeholder success:successBlock failure:failureBlock];
Expand Down
2 changes: 1 addition & 1 deletion Haneke/UIImageView+Haneke.h
Expand Up @@ -100,7 +100,7 @@
@discussion If needed, the least recently used images in the cache will be evicted in background.
@warning If a success block is provided you will be responsible for setting the image.
*/
- (void)hnk_setImage:(UIImage*)image withKey:(NSString*)key placeholder:(UIImage*)placeholder success:(void (^)(UIImage *image))successBlock failure:(void (^)(NSError *error))failureBlock;
- (void)hnk_setImage:(UIImage *)image withKey:(NSString *)key placeholder:(UIImage *)placeholder success:(void (^)(UIImage *fetchedImage))successBlock failure:(void (^)(NSError *error))failureBlock;

/** Loads, resizes, displays and caches an appropiately sized image from the given fetcher.
@param fetcher Fetcher from which the original image will be retrieved if needed. The fetcher will have to provide the original image only if it can't be found in the cache.
Expand Down
2 changes: 1 addition & 1 deletion Haneke/UIImageView+Haneke.m
Expand Up @@ -69,7 +69,7 @@ - (void)hnk_setImage:(UIImage*)originalImage withKey:(NSString*)key placeholder:
[self hnk_setImage:originalImage withKey:key placeholder:placeholder success:nil failure:nil];
}

- (void)hnk_setImage:(UIImage*)originalImage withKey:(NSString*)key placeholder:(UIImage*)placeholder success:(void (^)(UIImage *image))successBlock failure:(void (^)(NSError *error))failureBlock
- (void)hnk_setImage:(UIImage *)originalImage withKey:(NSString *)key placeholder:(UIImage *)placeholder success:(void (^)(UIImage *fetchedImage))successBlock failure:(void (^)(NSError *error))failureBlock
{
id<HNKFetcher> fetcher = [[HNKSimpleFetcher alloc] initWithKey:key image:originalImage];
[self hnk_setImageFromFetcher:fetcher placeholder:placeholder success:successBlock failure:failureBlock];
Expand Down
2 changes: 0 additions & 2 deletions Haneke/UIView+Haneke.m
Expand Up @@ -19,8 +19,6 @@
//

#import "UIView+Haneke.h"
#import "HNKCache.h"
#import <objc/runtime.h>

const CGFloat HNKViewFormatCompressionQuality = 0.75;
const unsigned long long HNKViewFormatDiskCapacity = 50 * 1024 * 1024;
Expand Down