Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Storage

Depot

Struct persistance framework for Swift. Simple as that:

let myStruct = MyStruct(...)

Depot.persist(myStruct, "cached_data")

if let retrievedStruct: MyStruct = Depot.retrieved("cached_data") {
  print("MyStruct is retrieved",unpackedCustomStruct)
} else {
  print("no struct retrieved")
}

Features:

Depot can store differnet types:

  • Structs
  • Arrays of structs
  • Nested structs
  • Enums with raw types

Installation

Installation for CocoaPods by adding the following line to your Podfile:

use_frameworks!

pod 'Depot'

Usage

Structs

To support persisting struct, a struct needs to implement PropertyListReadable protocol which includes the following functions:

init?(storehouse: Storehousable)
func propertyListRepresentation() -> [String: AnyObject]

init method that gets each property from the storehouse, and a propertyListRepresentation method that converts structs to Sictionary that can persisted:

struct Person: PropertyListReadable {
    let name: String
    let age: Float
    let id: Int
    
    init(name: String, age: Float, id: Int) {
        self.name = name
        self.age = age
        self.id = id
    }
    
    init?(storehouse: Storehousable) {
        self.name = storehouse.read(key: "name") ?? ""
        self.age = storehouse.read(key: "age") ?? 25.5
        self.id = storehouse.read(key: "id") ?? 22
    }
    
    func propertyListRepresentation() -> [String : AnyObject] {
        return [ "name": self.name, "age": self.age, "id": self.id ]
    }
}

License

Depot made available under the MIT license.

Credits

Depot is brought to you by Sameh Mabrouk

mabrouksameh@gmail.com

@same7mabrouk

About

Struct Persistence framework for Swift

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages