/LBCacheImage

Image cache library for iOS

Primary LanguageSwiftOtherNOASSERTION

LBCacheImage

LBCacheImage is an image caching library for iOS

How to use this library:

  • drag the LBCacheImage folder to your project.
  • import the CommonCrypto.h header to the Objective C bridging header file because the NSString class extension is using CommonCrypto for hashing.

This library offer:

  • asynchronous image download;
  • cache support (memory and disk) with the option to set the days to keep the cache on disk;
  • option to get the local path to an image.
  • create MD5,SHA1,SHA256 hash.

Classes and extensions to use:

I. UIImageView class extension:

  • this UIImageView class extension offers the option to set a URL string of the image location on the server;
  • the image is downloaded asynchronous in the background;
  • the image is saved on the disk in the caches directory;

Methods to use:

  • setImageWithURLString:placeholderImage: - download and cache the image
  • setImageWithURLString:placeholderImage:options: - download and cache the image
  • setImageWithURLString:placeholderImage:options:completionBlock: - download, cache and return the image
  • imageForURLString: - search the UIImage directly in cache (memory or disk), nil is returned if not found

There are 3 LBCacheImageOptions to use:

  • .Default - it first search the memory cache, if not found it search on the disk, if not found it will download asynchronous and cache it
  • .ReloadFromWebOrCache - it will try to reload the image from the web, if it fails it will load from local cache
  • .LoadOnlyFromCache - it will only search in memory and on the disk

II. LBCacheImage:

  • this class is used by the UIImageView class extension for the download but you can use it directly.

Options to use:

  • kDaysToKeepCache - stores the days to keep the images in cache
  • kDefaultHashType - stores the hash type declared in the NSString class extension and it has 3 values: .MD5, .SHA1, .SHA256

Methods to use:

  • imagePathLocationForURLString: - a string with the local path location of the image saved on disk or nil if the image for the URLString is not found
  • downloadImageFromURLString:options:progressBlock:completionBlock: - same as UIImageView class extension, cache and return the image
  • imageForURLString: - same as UIImageView class extension, search the UIImage directly in cache (memory or disk), nil is returned if not found

III. NSString class extension:

  • use this class extension to get hash value from a string.
  • there are 3 options available, MD5, SHA1 and SHA256

Methods to use:

  • lbHashMD5 - create an MD5 hash
  • lbHashSHA1 - create an SHA1 hash
  • lbHashSHA256 - create an SHA256 hash
  • lbHashWithType: - create a hash using the 3 available options

LICENSE

This content is released under the MIT License https://github.com/lucianboboc/LBCacheImage/blob/master/LICENSE.md

Enjoy!