Skip to content

Cache verify #47

@narlei

Description

@narlei

Hello,

In my project I add the block in - (UIImage_)imageForKey:(NSString_)key { :
if (!image && pathImage){
@Try {
NSData *data = [NSData dataWithContentsOfFile:pathImage];
image = [UIImage imageWithData:data];
} @catch (NSException *e1) {

        }
    }

if not success "[NSKeyedUnarchiver unarchiveObjectWithFile:pathImage]", then verify if can transform the data file in UIImage;

It's working very fine.

Can you add this in the project? Because I'm using cocoaPods in my project.

Thank you! This Class is wonderful.

  • (UIImage_)imageForKey:(NSString_)key {
    UIImage* image = nil;
    NSString _pathImage = nil;
    @Try {
    pathImage = cachePathForKey(directory, key);
    image = [NSKeyedUnarchiver unarchiveObjectWithFile:pathImage];
    } @catch (NSException
    e) {
    // Surpress any unarchiving exceptions and continue with nil
    if (!image && pathImage){
    @Try {
    NSData *data = [NSData dataWithContentsOfFile:pathImage];
    image = [UIImage imageWithData:data];
    } @catch (NSException *e1) {

        }
    }
    

    }

    return image;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions