8000 GitHub - vexy/Fridge: Handle your structs like a boss 🧞‍♂️
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

vexy/Fridge

Repository files navigation

❄️ Fridge ❄️

Fridge is Swift based freezing device.
It helps you fetch-n-store data without major hassle.

Lightweight, Async/Await friendly, Zero dependency, Foundation based.

Supported platforms

Platforms

Issues

Tests

Release build Tets build

💠 Library description

Fridge is a freezing device ❄️ so it has to keep things cool enough, exposing just icy interface.

Fridge is designed to reduce the pain with most common software operations such as fetching and storing data. Or something like this:

  • fetching your stuff from the network,
  • parsing or decoding (JSON) data,
  • doing boring error checking
  • storing the stuff somewhere on disk
  • doing boring error checking again
  • invoking more than 1 dependency for this (not using Fridge)
  • and yeah... even cursing old closures.
  • (not)doing tests

Fridge is so async/await friendly and designed with simplicity and flexibility in hand. With Fridge, you can even say goodbye to closures and CoreData if you want! 🤷🏻‍♂️

Checkout documentation for more information.

Talking is cheap. Show me the code. - Linus Torvalds

🕸 Networking

// define your endpoint
let endpoint = URL("https://github.com/vexy/")!

// conform your fancy struct to Decodable
struct GitHubRepoObject: Decodable {
  var name: String
  var repositoryURL: URL
  
  // ... some other fields
}

// use Fridge to grab🔮 data from the network endpoint
do {
  let myRepo: GitHubRepoObject = try await Fridge.grab🔮(from: endpoint)
  
  // do something with your object
  print(myRepo)
  print(myRepo.name)
} catch let err {
  print("Naaah.. Something bad happened: \(err)")
}

Checkout more documentation on networking or start with basic code examples.

💾 Persistant (local) storage

Fridge storage mechanics are built on Foundation principles and use BSON as internal storage mechanism. All you have to do is to conform your struct to Encodable and you're ready to go, Fridge will take care of the rest.

// conform your fancy struct to Decodable
struct GitHubRepoObject: Decodable {
  var name: String
  var repositoryURL: URL
}

// freeze it to local storage in just on line
do {
  try Fridge.freeze🧊(myRepo, id: "myIdentifier")
} catch let e {
  print("Whoops... Can't freeze because: \(e)")
}

Checkout documentation for more information.

Real world use cases

Here is some real world usage of Fridge:

  • Clmn - Beautiful macOS app that operates with tasks in columns
  • Sample code - with Fridge in practical usage

Installation instructions

Using Swift Package Manager is by far the sexiest way to install Fridge.

// swift-tools-version:5.3
import PackageDescription

let package = Package(
    name: "YOUR-PACKAGE",
    dependencies: [
        .package(url: "https://github.com/vexy/Fridge.git", .upToNextMajor(from: "0.9"))
    ],
    targets: [
        .target(name: "YOUR-TARGET", dependencies: ["Fridge"])
    ]
)

Quick links:

name: "Fridge"
url: "https://github.com/vexy/Fridge.git"
branch: "main"

Minimum versions required

For Fridge to work in full capacity, following Swift & iOS configuration is recommended:

  • Xcode 13.1+
  • Swift 5.5
  • iOS 15.0+
  • macOS 12.0

Recommended versions mentioned above area guaranteed to successfully build & test Fridge ✅.
If nothing else, you can always fire an issue if you stumble upon the way.

Although, you can even run Fridge with following: 😮

  • iOS 11.0+
  • macOS 10.14

...but you won't be able to grab🔮 things nor any of the fancy async/await things. Sorry 🤷🏻‍♂️

NOTEs
Be sure to meet minimum configuration parameters as you may encounter difficult-to-recover build errors on earlier configurations.
Sometimes, setting liker flag to -Xfrontend -enable-experimental-concurrency helps, but may fail if building with commandline.
That may be helpfull for Xcode 12.x, assuming Swift 5.x is installed.

Checkout official Swift.org website, for supporting earlier than minimums and other info.

External dependencies

Since v1.0 Fridge does not use anything other than Foundation provided JSONEncoder.
Up to v0.9.2 Fridge used BSONCoder v0.9 as main encoding device.

Documentation

RTFM isn't a joke... 🥴

In the Docs you'll quickly figure out how to:

  • easily fetch object from the network,
  • persistently store your objects,
  • load them back into your app,
  • catch nasty errors along the way
  • all other dirtly little secrets about the Fridge

Check usage examples or entire Guides collection for more goodies.
Xcode Playground file can be found here. For a bigger picture overview, feel free to check architecture diagrams... ∰

Contribution guidelines

If you like Fridge, feel free to fire a pull request. The prefered way is to branch off the main branch, complete feature or a fix and then merge to development. After the pull request has been approved, your change will be merged to main.

Don't be affraid to start any discussions if you think so.
Issues section is a good way to start, if you stumble upon the way.


(FRIDGE IS UNDER ACTIVE DEVELOPMENT ALMOST REACHING v1.0)
Fridge BETA release : v0.9.3 ( UTC2022-09-24 )

Copyright © 2016 Veljko Tekelerović | MIT license
PGP: 6302 D860 B74C BD34 6482 DBA2 5187 66D0 8213 DBC0

Fridge - Lightweight, fast and extreeemely simple to use fetch or store mechanism.
profile for Vexy on Stack Exchange, a network of free, community-driven Q&A sites

0