SwiftStore: A key-value store for Swift backed by LevelDB

There’s no shortage of databases available for the web. MongoDB, Postgres, MySQL, RethinkDB. The list goes on.

What about mobile apps? What options are there if you want to integrate a database for your mobile application? Popular ones include SQLite, CoreData, and Realm.

With SQLite, you think in terms of tables and queries. CoreData is needlessly complicated. Parse used to be big until last year. Now it’s defunct.

Realm, on the other hand looks awesome. If i had to choose a database library today, It would be my first choice.

When I was developing the OpenLearning IOS app a few years ago, I was looking for an embedded NoSQL database with first-class JSON support. I couldn’t find one so I built one for myself. To be more specific, I built one on top of LevelDB that integrated with Swift easily.

What abstraction does SwiftStore come with? The simplest of them all —Key-Value pair, a.k.a Dictionary in Swift, HashMap in Java, and Map in Go.

// Set a value
DB.store["username"] = "jondoe"

Cool.

How easy is it to integrate with Swift? There are three steps:

  • Install the library. Head over here for details.
  • Extend the SwiftStore class.
class DB : SwiftStore {
/* Shared Instance */
static let store = DB()

init() {
super.init(storeName: "db")
}

override func close() {
super.close()
}
}
  • Init the database in the didFinishLaunchingWithOptions in the AppDelegate.

References

https://github.com/hemantasapkota/SwiftStore

--

--

Creator of Yolmo: Learn to Code app — https://yolmo.com | React Native Pro - https://reactnativepro.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store