Skip to content

Commit

Permalink
Update CodableArchiver.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
rismay committed Nov 17, 2024
1 parent 7c8db8c commit c9d3c51
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions Sources/WrkstrmFoundation/Persistence/CodableArchiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct CodableArchiver<T: Codable> {
self.encoder = encoder
self.decoder = decoder
// swiftlint:disable:next force_unwrapping
let archiveDirectory = fileManager.urls(for: directory, in: searchPathDomainMask).first!
let archiveDirectory: URL = fileManager.urls(for: directory, in: searchPathDomainMask).first!
self.archiveDirectory = archiveDirectory.appendingPathComponent(String(key.description))
self.key = key
}
Expand All @@ -62,23 +62,19 @@ public struct CodableArchiver<T: Codable> {
archiveDirectory = directory.deletingLastPathComponent()
key = directory.lastPathComponent
}
}

// MARK: - Filemanager helpers
// MARK: - Filemanager helpers

extension CodableArchiver {
/// Returns the file path for a given key within the archive directory.
///
/// - Parameter key: The key for which to generate the file path.
/// - Returns: The file path as a `String`.
public func filePathForKey(_ key: AnyHashable) -> String {
archiveDirectory.appendingPathComponent(String(key.description)).path
}
}

// MARK: - Workflow operations
// MARK: - Workflow operations

extension CodableArchiver {
/// Retrieves and decodes an object of type `T` associated with the given key.
///
/// - Parameter key: The key for the object to retrieve. Defaults to the archiver's key.
Expand Down Expand Up @@ -123,7 +119,7 @@ extension CodableArchiver {
///
/// - Parameters:
/// - value: The array of objects to archive.
/// - key: The key to associate with the objects. Defaults to the archiver's key.
/// - key: The key to associate with the objects. Default s to the archiver's key.
/// - Returns: A `Bool` indicating success or failure.
@discardableResult
public func set(_ value: [T], forKey key: AnyHashable? = nil) -> Bool {
Expand Down

0 comments on commit c9d3c51

Please sign in to comment.