{"id":15594375,"url":"https://github.com/orta/fastimagecacheexample","last_synced_at":"2025-05-06T19:14:02.671Z","repository":{"id":66647022,"uuid":"19008153","full_name":"orta/FastImageCacheExample","owner":"orta","description":"The simplest possible use of FastImageCache","archived":false,"fork":false,"pushed_at":"2014-04-21T22:20:24.000Z","size":360,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-06T19:13:57.859Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-21T21:48:34.000Z","updated_at":"2019-08-13T15:40:10.000Z","dependencies_parsed_at":"2023-02-20T09:30:59.795Z","dependency_job_id":null,"html_url":"https://github.com/orta/FastImageCacheExample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orta%2FFastImageCacheExample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orta%2FFastImageCacheExample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orta%2FFastImageCacheExample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orta%2FFastImageCacheExample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orta","download_url":"https://codeload.github.com/orta/FastImageCacheExample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252752059,"owners_count":21798723,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T00:39:11.279Z","updated_at":"2025-05-06T19:14:02.645Z","avatar_url":"https://github.com/orta.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"FastImageCacheExample\n=====================\n\nThe simplest possible use of FastImageCache: Throwing a single bundled image on the screen.\n\nI didn't write [FastImageCache](https://github.com/path/FastImageCache).\n\n### Overall\n\nSetup the `FICImageCache` somewhere, an easy place to start it App Delegate\n\n``` objc\n    // Configure the image cache\n    FICImageCache *sharedImageCache = [FICImageCache sharedImageCache];\n    [sharedImageCache setDelegate:self];\n\n    // Reuse the Path image formats\n    FICImageFormatDevices squareImageFormatDevices = FICImageFormatDevicePhone | FICImageFormatDevicePad;\n    FICImageFormat *squareImageFormat16BitBGR = [FICImageFormat formatWithName:FICDPhotoSquareImage16BitBGRFormatName family:FICDPhotoImageFormatFamily\n                                                                     imageSize:FICDPhotoSquareImageSize style:FICImageFormatStyle16BitBGR\n                                                                  maximumCount:250 devices:squareImageFormatDevices protectionMode:FICImageFormatProtectionModeNone];\n    \n    [sharedImageCache setFormats:@[squareImageFormat16BitBGR]];\n```\n\nWherever this class is it needs to do the work of connecting an \u003cFICEntity\u003e to a UIImage. \n\t\n``` objc\n- (void)imageCache:(FICImageCache *)imageCache wantsSourceImageForEntity:(id\u003cFICEntity\u003e)entity withFormatName:(NSString *)formatName completionBlock:(FICImageRequestCompletionBlock)completionBlock {\n    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{\n\n        NSURL *filePathURL = [entity sourceImageURLWithFormatName:formatName];        \n        UIImage *sourceImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:filePathURL]];\n        \n        dispatch_async(dispatch_get_main_queue(), ^{\n            completionBlock(sourceImage);\n        });\n    });\n}\n\n```\n\nYou have to include the other methods, these will probably come in useful later:\n\n``` objc\n- (BOOL)imageCache:(FICImageCache *)imageCache shouldProcessAllFormatsInFamily:(NSString *)formatFamily forEntity:(id\u003cFICEntity\u003e)entity {\n    return NO;\n}\n\n- (void)imageCache:(FICImageCache *)imageCache errorDidOccurWithMessage:(NSString *)errorMessage {\n    NSLog(@\"%@\", errorMessage);\n}\n```\n\nYou now need an object that conforms to the `\u003cFICEntity\u003e` protocol. Here's a gotcha for me. _The UUIDs have to go through `FICUUIDBytesFromMD5HashOfString` \u0026 `FICStringWithUUIDBytes` before they get matched correctly, if they don't it will silently not find your image._ I initially used a string here. Read [their readme](https://github.com/path/FastImageCache#creating-entities) for more info.\n\t\n```objc\n@interface ORImage : NSObject \u003cFICEntity\u003e\n\n@property (nonatomic, copy) NSString *filename;\n\n@end\n```\n\nYou can't skip `drawingBlockForImage:withFormatName:` even if you're just redrawing the image.\n\n``` objc\n@implementation ORImage {\n    NSString *_UUID;\n}\n\n- (NSString *)UUID\n{\n    if (_UUID == nil) {\n        CFUUIDBytes UUIDBytes = FICUUIDBytesFromMD5HashOfString(self.filename);\n        _UUID = FICStringWithUUIDBytes(UUIDBytes);\n    }\n    return _UUID;\n\n}\n\n- (NSString *)sourceImageUUID\n{\n    return self.UUID;\n}\n\n- (NSURL *)sourceImageURLWithFormatName:(NSString *)formatName \n{\n    return [[NSBundle mainBundle] URLForResource:self.filename withExtension:@\"jpg\"];\n}\n\n- (FICEntityImageDrawingBlock)drawingBlockForImage:(UIImage *)image withFormatName:(NSString *)formatName \n{\n    FICEntityImageDrawingBlock drawingBlock = ^(CGContextRef context, CGSize contextSize) {\n        CGRect contextBounds = CGRectZero;\n        contextBounds.size = contextSize;\n        CGContextClearRect(context, contextBounds);\n        \n        UIGraphicsPushContext(context);\n        [image drawInRect:contextBounds];\n        UIGraphicsPopContext();\n    };\n    \n    return drawingBlock;\n}\n\n```\n\nNext you need to make sure you have your image table formats set up correctly, I reused more of Paths:\n\n``` objc\nNSString *const FICDPhotoImageFormatFamily = @\"FICDPhotoImageFormatFamily\";\nNSString *const FICDPhotoSquareImage16BitBGRFormatName = @\"com.path.FastImageCacheDemo.FICDPhotoSquareImage16BitBGRFormatName\";\nCGSize const FICDPhotoSquareImageSize = {240, 240};\n```\n\nand \n\n``` objc\nextern NSString *const FICDPhotoSquareImage16BitBGRFormatName;\nextern NSString *const FICDPhotoImageFormatFamily;\n```\n\nWith all this set up you're now ready to call something like this to get an image from the cache:\n\n``` objc\nself.image = [[ORImage alloc] init];\nself.image.filename = @\"pizza\";\n\n[[FICImageCache sharedImageCache] retrieveImageForEntity:self.image withFormatName:FICDPhotoSquareImage16BitBGRFormatName completionBlock:^(id\u003cFICEntity\u003e entity, NSString *formatName, UIImage *image) {\n    [self.imageView setImage:image];\n}];\n```\n\nAnd you've got the first image going through the FIC pipeline, now you build from there.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forta%2Ffastimagecacheexample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forta%2Ffastimagecacheexample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forta%2Ffastimagecacheexample/lists"}