SBSDKIndexedImageStorage
@interface SBSDKIndexedImageStorage : NSObject <SBSDKImageStoring>
A simple thread-safe multiple-reader-single-writer index based disk image cache class. Manages images in an array-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. 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 }
-
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 }
-
Image file format to be used to store the managed images.
Declaration
Objective-C
@property (nonatomic, readonly) SBSDKImageFileFormat fileFormat;
Swift
var fileFormat: SBSDKImageFileFormat { get }
-
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
SBSDKAESEncrypter
for reference.Declaration
Objective-C
@property (nonatomic, strong, nullable) id<SBSDKStorageCrypting> encrypter;
Swift
var encrypter: SBSDKStorageCrypting? { get set }
-
Initializes a new ‘SBSDKIndexedImageStorage’ at a temporary location (application caches folder). On deallocation the receiver will remove all its files from the file system.
Declaration
Objective-C
+ (nullable instancetype)temporaryStorage;
Swift
class func temporary() -> Self?
Return Value
A new ‘SBSDKIndexedImageStorage’ instance.
-
Initializes a new ‘SBSDKIndexedImageStorage’ 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 ‘SBSDKIndexedImageStorage’ instance at the given storage location.
-
Initializes a new ‘SBSDKIndexedImageStorage’ 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 ‘SBSDKIndexedImageStorage’ instance at the given storage location.
-
Initializes a new ‘SBSDKIndexedImageStorage’ 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 encryptedImagesURLs:(NSArray<NSURL *> *_Nonnull)encryptedImageURLs;
Swift
init?(storageLocation: SBSDKStorageLocation?, fileFormat: SBSDKImageFileFormat, withEncrypter encrypter: SBSDKStorageCrypting?, encryptedImagesURLs encryptedImageURLs: [URL])
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.
encryptedImageURLs
Array of URLs containing encrypted images. The images at these URLs must be encrypted with the given encrypter (if not nil) and must have the same file format as specified in the fileFormat parameter.
Return Value
A new ‘SBSDKIndexedImageStorage’ instance at the given storage location.
-
Adds a new image to the receiver.
Declaration
Objective-C
- (BOOL)addImage:(nonnull UIImage *)image;
Swift
func add(_ image: UIImage) -> Bool
Parameters
image
The UIImage to be managed by the receiver.
Return Value
YES, if the operation was successfull, NO otherwise.
-
Adds a new image to the receiver.
Declaration
Objective-C
- (BOOL)addImageFromURL:(nonnull NSURL *)url;
Swift
func addImage(from url: URL) -> Bool
Parameters
url
The URL the image is read from.
Return Value
YES, if the operation was successfull, NO otherwise.
-
Returns the image at the given index.
Declaration
Objective-C
- (nullable UIImage *)imageAtIndex:(NSUInteger)index;
Swift
func image(at index: UInt) -> UIImage?
Parameters
index
The valid index at which the requested image is located at.
Return Value
The stored UIImage or nil, if there was no image at that index.
-
Returns the images file URL at the given index.
Note: If the storage is encrypted, the data at this URL is encrypted and must be properly decrypted before being used.
Declaration
Objective-C
- (nullable NSURL *)imageURLAtIndex:(NSUInteger)index;
Swift
func imageURL(at index: UInt) -> URL?
Parameters
index
The valid index at which the requested image is located at.
Return Value
The URL of the image file or nil, if there was no image at that index.
-
Inserts a new image into the receiver at the given index.
Declaration
Objective-C
- (BOOL)insertImage:(nonnull UIImage *)image atIndex:(NSUInteger)index;
Swift
func insert(_ image: UIImage, at index: UInt) -> Bool
Parameters
image
The UIImage to be managed by the receiver.
index
The valid index at which the new image should be inserted.
Return Value
YES, if the operation was successfull, NO otherwise.
-
Moves the image at the source index to the destination index.
Declaration
Objective-C
- (BOOL)moveImageFromIndex:(NSUInteger)sourceIndex toIndex:(NSUInteger)destinationIndex;
Swift
func moveImage(from sourceIndex: UInt, to destinationIndex: UInt) -> Bool
Parameters
sourceIndex
The valid current index of the image to be moved.
destinationIndex
The valid new index of the image to be moved.
Return Value
YES, if the operation was successfull, NO otherwise.
-
Replaces the receivers image at index with the given image.
Declaration
Objective-C
- (BOOL)replaceImageAtIndex:(NSUInteger)index withImage:(nonnull UIImage *)image;
Swift
func replaceImage(at index: UInt, with image: UIImage) -> Bool
Parameters
index
The valid current index of the image to be replaced.
image
The new image that should be stored at the given index.
Return Value
YES, if the operation was successfull, NO otherwise.
-
Replaces the receivers image at index with the image stored at the given URL.
Declaration
Objective-C
- (BOOL)replaceImageAtIndex:(NSUInteger)index withImageAtURL:(nonnull NSURL *)url;
Swift
func replaceImage(at index: UInt, withImageAt url: URL) -> Bool
Parameters
index
The valid current index of the image to be replaced.
url
The URL of the new image that should be stored at the given index.
Return Value
YES, if the operation was successfull, NO otherwise.
-
Removes the image at the given index from the receiver as well as from the the file system.
Declaration
Objective-C
- (void)removeImageAtIndex:(NSUInteger)index;
Swift
func removeImage(at index: UInt)
Parameters
index
The valid index of the image to 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()