Choosing a way for storing data permanently is something that is always needed when developing applications. There are various options we can pick from: To create single files, to use CoreData or create a SQLite database. The last option includes some extra hassle as the database must be created first, and all tables and fields to be already defined before an app uses them. Furthermore, and from the programming point of view, it’s not that easy to manage a SQLite database when data needs to be stored, updated or retrieved.
Those problems seem to disappear when using a relatively new library that was popped on the GitHub called SwiftyDB. It’s a third-party library, which, as the creator says, is a plug-and-play component indeed. SwiftyDB reliefs developers from the hassle of creating a SQLite database manually, and from defining all required tables and fields. That happens automatically by the library using the properties of the class (or classes) used as data models. Besides that, all database operations are performed under the hood, so developers can focus on the implementation of the app logic only. A simple yet powerful API makes it really a piece of cake when dealing with the database.
It’s necessary to mention though that you shouldn’t expect SwiftyDB to make miracles. It’s a reliable library that can do pretty well what it’s supposed to do, but there are still some missing features that are probably meant to be added in the (near or distant) future. However, it’s still remaing a great tool that deserves some special attention, therefore in this tutorial we’ll go through the basics of SwiftyDB.
For your reference, you can find its documentation here, which you should definitely see after having gone through this text. If you were always willing to work with SQLite databases but hesitated to do so, I believe that SwiftyDB is a good start to do that.
With the above said, let’s get going with the exploration of a new, quite promising tool.