Skip to content

Commit

Permalink
Added (missing) support for array into main Fridge interface
Browse files Browse the repository at this point in the history
  • Loading branch information
vexy committed Sep 24, 2022
1 parent 8a84b5f commit 523930d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Sources/Fridge/Freezer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ final internal class Freezer {
}
}

//MARK: --

/// Unfreezes an object from Fridge persistant storage.
func unfreeze<T: Decodable>(identifier: String) throws -> T {
do {
Expand Down
22 changes: 21 additions & 1 deletion Sources/Fridge/Fridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extension Fridge {

//MARK: - Object persistent storage
extension Fridge {
/// Tries to freeze an object into persistant storage (if possible).
/// Tries to freeze an object into persistant storage.
public static func freeze🧊<E: Encodable>(_ object: E, id: String) throws {
let freezer = Freezer()
do {
Expand All @@ -121,12 +121,32 @@ extension Fridge {
}
}

/// Tries to freeze array of objects into persistant storage.
public static func freeze🧊<C: Codable>(_ objects: [C], id: String) throws {
let freezer = Freezer()
do {
try freezer.freeze(objects: objects, identifier: id)
} catch let err {
print("<Fridge.Freezer> Error occured: \(err.localizedDescription)")
throw FreezingErrors.dataStoringError
}
}

//MARK: --

/// Tries to unfreeze an object from persistant storage.
public static func unfreeze🪅🎉<D: Decodable>(_ key: String) throws -> D {
let unfreezer = Freezer()
let unfrozenObject: D = try unfreezer.unfreeze(identifier: key) // propagate any Errors further
return unfrozenObject
}

/// Tries to unfreeze an array of objects from persistant storage.
public static func unfreeze🪅🎉<C: Codable>(_ key: String) throws -> [C] {
let unfreezer = Freezer()
let unfrozenObject: [C] = try unfreezer.unfreeze(identifier: key) // propagate any Errors further
return unfrozenObject
}
}

//MARK: - Utilities
Expand Down

0 comments on commit 523930d

Please sign in to comment.