diff --git a/README.md b/README.md index 9539d98..d31c292 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ import PixieCacheKit struct MyApp: App { init() { // Configure to use a custom directory for file-based image caching. - PixieCacheKit.configure(directoryName: "MyAppCache") + PixieCacheKit.configure(directoryName: "MyAppCache", imageFormat: .jpeg) // OR diff --git a/Sources/PixieCacheKit/Internal/CacheManager.swift b/Sources/PixieCacheKit/Internal/CacheManager.swift index c5f0c7b..0ffd495 100644 --- a/Sources/PixieCacheKit/Internal/CacheManager.swift +++ b/Sources/PixieCacheKit/Internal/CacheManager.swift @@ -23,7 +23,8 @@ public class CacheManager { /// The name of the cache directory used by PixieCacheKit for file-based image caching. public var cacheDirectoryName = "PixieImageCache" - + public var imageFormat: ImageFormat = .jpeg + /// Create a directory if it doesn't exist at the specified path. public func createCacheDirectory() { // Directory path. @@ -50,7 +51,7 @@ public class CacheManager { private func getImagePath(key: String) -> URL? { guard let cacheURL = getCacheDirectoryPath() else { return nil } - return cacheURL.appendingPathComponent(key + ".jpeg") + return cacheURL.appendingPathComponent(key + imageFormat.rawValue) } /// Append an image in the specified directory with the given key(name). diff --git a/Sources/PixieCacheKit/Internal/ImageFormat.swift b/Sources/PixieCacheKit/Internal/ImageFormat.swift new file mode 100644 index 0000000..1c2825c --- /dev/null +++ b/Sources/PixieCacheKit/Internal/ImageFormat.swift @@ -0,0 +1,17 @@ +// ImageFormat.swift +// +// Author: Aum Chauhan +// Date: 25/8/2023 +// GitHub: https://github.com/aum-chauhan-175 + +import Foundation + +@available(iOS 15.0, *) +/// Enumeration representing supported image formats in PixieCacheKit. +public enum ImageFormat: String { + /// `jpeg` stores images in .jpeg format. + case jpeg = ".jpeg" + + /// `png` stores images in .png format. + case png = ".png" +} diff --git a/Sources/PixieCacheKit/Public/PixieCacheKit.swift b/Sources/PixieCacheKit/Public/PixieCacheKit.swift index bc4d8cc..d8d0f18 100644 --- a/Sources/PixieCacheKit/Public/PixieCacheKit.swift +++ b/Sources/PixieCacheKit/Public/PixieCacheKit.swift @@ -11,11 +11,16 @@ public struct PixieCacheKit { private init() { } /// Configure PixieCacheKit to use a custom directory for file-based image caching. - /// - Parameter directoryName: The name of the custom cache directory. - public static func configure(directoryName: String) { + /// - Parameters: + /// - directoryName: The name of the custom cache directory. + /// - imageFormat: Choose the image format (`.jpeg` & `.png`) for file manager caching. + public static func configure(directoryName: String, imageFormat: ImageFormat) { // Configuring directory name CacheManager.shared.cacheDirectoryName = directoryName + // Configuring image format + CacheManager.shared.imageFormat = imageFormat + // Configuring storage location. CacheManager.shared.storageLocation = .fileManager