Latest 2.0.0
License MIT
Platforms ios 11.0
Dependencies Disk

Cocoapods compatible


The CodeablePersistenceStore is basically a Disk wrapper. It makes our lives easier while working with the new Codable Type which was introduced in Swift 4.


The CodablePersistenceStore requires iOS 9+ and is compatible with Swift 4 projects. Therefore you must use Xcode 9.


The usage is pretty straight forward. All you have to do is to let a model implement the Persistable Type Protocol which comes down with the CodablePersistenceStore import.

All of the methods you see in the documentation can throw. So don’t forget to handle exceptions.


    import CodablePersistenceStore

    // Its an example.
    struct Message: PersistableType {

    let id: String
    let title: String
    let body: String

     init(id: String, title: String, body: String) { = id
       self.title = title
           self.body = body

     func identifier() -> String {


To actually persist data all you have to do is create an object from your model and put it into the persist method. There are currently two types of persist methods. The first one is synchronous, the second one is asynchronous.

let message = Message(id: "10", title: "Hello", body: "World!")

Thats basically all you gotta do. Theres also a version with a completion handler to do things afterwards.

 let message = Message(id: "10", title: "Hello", body: "World")
 self.persistenceStore.persist(message, completion: { 
      // do some stuff afterwards


Retrieving your persisted data is pretty straight forward. There are always synchronous and asynchronous methods.

let message = self.persistenceStore.get("id", type: Message.self)

That simple.

If you want it to be asynchronous, there you go:

self.persistenceStore.get("id", type: Message.self, completion: { (message) in 
    // your message should be here right now

If you got tons of messages for example and you want them all you could just call the following method:

let messages = self.persistenceStore.getAll(Message.self)

Or asynchronous:

self.persistenceStore.getAll(Message.self, completion: { (messages) in 
    // your messages should be here


There are a few ways to delete items. Its pretty self explaining.
Imagine you already got some persisted messages.


Of course there is a version which lets you do things after deleting something (e.g. reloading tableview)

self.persistenceStore.delete(message, completion: { 
    // do things afterwards

But there is another version which needs an identifier and the type you want to delete.

self.persistenceStore.delete("10", type: Message.self)

With completion:

self.persistenceStore.delete("10", type: Message.self, completion: {
    // do things afterwards


You can filter all your items from the same type by properties. For example:

let itemWithID10 = self.persistenceStore.filter(Message.self, includeElement: { (item: Message) -> Bool in
        return == "10"

Or asynchronous:

self.persistenceStore.filter(Message.self, includeElement: { (item: Message) -> Bool in
     return == "10" 
}, completion: { (item) in


You could check right before persisting some data if the item you’re about to persist already exists in the store:

let isAlreadyInStore = self.persistenceStore.exists(message1)


self.persistenceStore.exists(message1, completion: { (bool) in 
    guard bool == false else { return }
        // do stuff afterwards

More options:

let isAlreadyInStore = self.persistenceStore.exists("10", type: Message.self)

Or Async:

self.persistenceStore.exists("10", type: Message.self, completion: { (bool) in 
    guard bool == false else { return }
        // to stuff afterwards


To clear the whole cache, all you’ve to do is call:



To integrate the CodablePersistenceStore into your Xcode project using CocoaPods, specify it in your Podfile:

source ''
platform :ios, '11.0'

target '<Your Target Name>' do
    pod 'CodablePersistenceStore'

Then, run the following command:

$ pod install


Mario Zimmermann, [email protected]


The CodablePersistenceStore is released under the MIT license.

Latest podspec

    "name": "CodablePersistenceStore",
    "version": "2.0.0",
    "summary": "A Disk wrapper which makes your live easier while working with the new Codable Type.",
    "homepage": "",
    "license": "MIT",
    "authors": {
        "Mario Zimmermann": "[email protected]"
    "source": {
        "git": "",
        "tag": "2.0.0"
    "social_media_url": "",
    "platforms": {
        "ios": "11.0"
    "source_files": "CodablePersistenceStore/Classes/**/*",
    "dependencies": {
        "Disk": [
            "~> 0.3.3"
    "pushed_with_swift_version": "4.0"

Pin It on Pinterest

Share This