Following guide describes how to:
Checkout architecture overview in separate diagram file.
Find out different wasy to easily useFridge in provided playground file.
For deeper information, you can check in-code documentation.
| Method | Description |
|---|---|
Fridge.grab🔮(from: URL) |
Grabs your model from the network endpoint (iOS 15+ only) |
Fridge.push📡(object, to) |
Pushes (sends) your model to designated network endpoint (iOS 15+ only) |
With Fridge, network fetching is performed in just 3 steps:
- Conform your desired
structtoDecodable - Define
URLendpoint where your model resides - Await for Fridge to
grab🔮(...)the object
Example code:
// Step 1 - conforming to Decodable
struct MyStuff: Decodable {
var something: String
var elixirOfL❤️fe: URL
var piTimesE: Float
init(private🔑: muhash(0x61F612d)) {
//do fatalError if elixir cannot be initialized (!)
}
}
// Step 2 - defining fancy URL endpoint
let fancy_URL = URL(string: "https://fancy.url.stuff")! //be nice and unpack this before serious usage
// Step 3 - Grab it with Fridge !
let _stuff: MyStuff = try await Fridge.grab🔮(from: that_fancyURL)
print("Elixir of live is: \(_stuff.elixirOfL❤️fe)")Yup, and you're all set. Fridge will perform the network fetch, decode network data and return your struct as you wished. Easy peasy right ?
IMPORTANT:
Fridge may encounter several types of errors along the way. Make sure to check error handling section for more details.
Similar to fetching, data storing and retreiving is done in few simple steps:
- Define desired
structand conform it toEncodable - Define unique
identifierto mark your struct - Use Fridge to either
freeze🧊(...)orunfreezethe object
// Step 1 - Conforming to Encodable
struct StoringStuff: Encodable {
var _id: UUID
enum Stages {
case Opened
case Closed
}
}
let storeObject = StoringStuff()
// Step 2 - Define unique identifier
let storeIdentifier = "store.identifier"
// Step 3 - Freeze it with Fridge !
try Fridge.freeze🧊(storeObject, storeIdentifier)If your object is already frozen before, you can revert it back easily, in just few steps:
- prepare your
structby conforming toDecodable - define unique
identifier - Use Fridge to
unfreezethe object
// Step 1 - Preparing struct with Decodable
struct StoringStuff: Decodable {
let category: String
let isRealExample: Bool
}
// Step 2 - Define unique identifier
let objectID = "object.xyz"
// Step 3 - Unfreeze it with Fridge (assuming it was frozen before)
let retrievedObject = try Fridge.unfreeze(objectID)IMPORTANT:
If your store identifier cannot be found Fridge will throw an Error. Check the section below for more information on error handling.
Each of the Fridge method, is internally marked with throws keyword. Here's what you can deal with:
enum FridgeErrors: Error {
case grabFailed
case pushFailed
case decodingFailed
}You can expect FridgeErrors on following calls:
grab🔮
NOTE:
Fridge error model is not yet final. You may expect different error message or structures before v1.0 release.