SBSDKKeyedImageStorage

@interface SBSDKKeyedImageStorage : NSObject

A simple thread-safe multiple-reader-single-writer key-value fashioned disk image cache class. Manages images in a dictionary-like fashion.

  • The number of stored images.

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSUInteger imageCount;

    Swift

    var imageCount: UInt { get }
  • Array of all stored images URLs (values). Note: If the storage is encrypted, the data at these URLs are encrypted and must be properly decrypted before being used.

    Declaration

    Objective-C

    @property (nonatomic, readonly, nonnull) NSArray<NSURL *> *imageURLs;

    Swift

    var imageURLs: [URL] { get }
  • Array of all stored keys.

    Declaration

    Objective-C

    @property (nonatomic, readonly, nonnull) NSArray<NSString *> *imageKeys;

    Swift

    var imageKeys: [String] { get }
  • Image file format to be used to store the managed images.

    Declaration

    Objective-C

    @property (nonatomic, readonly) SBSDKImageFileFormat fileFormat;

    Swift

    var fileFormat: SBSDKImageFileFormat { get }
  • The JPEG compression if JPEG file format is used. Range: 0.0 - 1.0.

    Declaration

    Objective-C

    @property (nonatomic) CGFloat jpegCompressionQuality;

    Swift

    var jpegCompressionQuality: CGFloat { get set }
  • Encrypter used to encrypt and decrypt the image data. If nil, no encryption/decryption is used.

    Note: When using encryption you still can access the unencrypted images in the receiver. Of course, encrypted storages cannot be read without the proper encrypter being set here. You are responsible for migrating image storages.

    Defaults to nil: no encryption is used.

    See SBSDKAESEncrypterfor reference.

    Declaration

    Objective-C

    @property (nonatomic, readonly, nullable) id<SBSDKStorageCrypting> encrypter;

    Swift

    var encrypter: SBSDKStorageCrypting? { get }
  • Initializes a new ‘SBSDKKeyedImageStorage’ at the given storage location.

    Declaration

    Objective-C

    - (nullable instancetype)initWithStorageLocation:
        (nullable SBSDKStorageLocation *)storageLocation;

    Swift

    init?(storageLocation: SBSDKStorageLocation?)

    Parameters

    storageLocation

    The storage location at which the new storage should reside.

    Return Value

    A new ‘SBSDKKeyedImageStorage’ instance at the given storage location.

  • Initializes a new ‘SBSDKKeyedImageStorage’ at the given storage location with given image file format.

    Declaration

    Objective-C

    - (nullable instancetype)
        initWithStorageLocation:(nullable SBSDKStorageLocation *)storageLocation
                     fileFormat:(SBSDKImageFileFormat)fileFormat
                  withEncrypter:(nullable id<SBSDKStorageCrypting>)encrypter;

    Swift

    init?(storageLocation: SBSDKStorageLocation?, fileFormat: SBSDKImageFileFormat, withEncrypter encrypter: SBSDKStorageCrypting?)

    Parameters

    storageLocation

    The storage location at which the new storage should reside.

    fileFormat

    The file format that should be used to store the images.

    encrypter

    The encrypter used to encrypt/decrypt image data. If nil, no encryption is used.

    Return Value

    A new ‘SBSDKKeyedImageStorage’ instance at the given storage location.

  • Stores an image at the given key.

    Declaration

    Objective-C

    - (void)setImage:(nonnull UIImage *)image forKey:(nonnull NSString *)key;

    Swift

    func setImage(_ image: UIImage, forKey key: String)

    Parameters

    image

    The UIImage to be managed by the receiver.

    key

    The key at which to store the image. Key must contain at least one character. Allowed are alphanumeric characters, dash and underscore. Passing an invalid key will throw an NSInvalidArgumentException.

  • Returns the image file URL for given key.

    Declaration

    Objective-C

    - (nullable NSURL *)imageURLForKey:(nonnull NSString *)key;

    Swift

    func imageURL(forKey key: String) -> URL?

    Parameters

    key

    The key at which the requested image was stored.

    Return Value

    A URL in the file system pointing to the image file or nil, if there was no image at that key. Caution: Do not perform any write operations at that URL! Note: If the storage is encrypted, the data at that URL is encrypted and must be properly decrypted before it can be used.

  • Returns the image for given key.

    Declaration

    Objective-C

    - (nullable UIImage *)imageForKey:(nonnull NSString *)key;

    Swift

    func image(forKey key: String) -> UIImage?

    Parameters

    key

    The key at which the requested image was stored.

    Return Value

    The stored UIImage or nil, if there was no image at that key. Caution: Do not perform any write operations at that URL!

  • Removes the image at the given key from the receiver as well as from the file system.

    Declaration

    Objective-C

    - (void)removeImageForKey:(nonnull NSString *)key;

    Swift

    func removeImage(forKey key: String)

    Parameters

    key

    The key for the image that should be removed.

  • Removes the images at keys from the receiver as well as from the file system, which keys prefix match the prefix string.

    Declaration

    Objective-C

    - (void)removeImagesForKeysMatchingPrefix:(nonnull NSString *)prefix;

    Swift

    func removeImagesForKeys(matchingPrefix prefix: String)

    Parameters

    prefix

    The prefix of the keys for the images that should be removed.

  • Removes all stored images from the receiver as well as from the file system.

    Declaration

    Objective-C

    - (void)removeAllImages;

    Swift

    func removeAllImages()
  • Blocks the current thread until all enqueued writing operations have been finished.

    Declaration

    Objective-C

    - (void)waitUntilWritingCompleted;

    Swift

    func waitUntilWritingCompleted()