DEV Community

Midhet Sulemani
Midhet Sulemani

Posted on • Updated on

Core Data vs. SQLite

Making an iOS application is all fun until you have to start maintaining offline user sessions and preferences on the app. Then comes the age old question.

Core Data/SQLite or something else?

So I want to share some of my insights on the topic.

Let’s start with Core Data,

  • Graph framework for maintaining objects and their relationships with each other.
  • Stores its data into a SQLite DB but is not a database in itself.
  • Manages and updates objects automatically in the memory. Can handle a complex graph of objects without any pressure/load on the memory management system of the device.
  • Has object versioning system in place which lets you update the object entities and attributes without deleting the previous data.
  • Is an Apple created framework, so is automatically updated with any updates in Swift. And now for SQLite,

SQLite is a persistent database model, which make a database and stores it in the file management system of your phone’s application.

  • It could be used for more lightweight models since its memory management will be dependent on the CocoaPods or Frameworks that have been used.
  • SQLite Pods or third party providers are easier to use and easier to grasp.
  • Can be created and updated just by writing a few custom queries. There are many Pods for SQLite in the market but one of the most popular and most stable is SQLite3.

There are pros and cons to both the frameworks and it all depends upon your requirements.
If you have enough time to configure a data persistence system, do dig into the Core Data option too.

There is another newer and faster option on the internet called Realm. I can’t really comment on it since I haven’t worked with it. It supports most platforms like Android, Swift, ObjC as well as React Native.

Since there are not many Getting Started with Core Data tutorials that I have come across, So I will be making one myself!

Top comments (4)

kesprit profile image

Good post, we can mention UserDefault too to store light weight datas, it can be very powerfull.

In my company, we use GRDB, it's a light third-part for SQLite.
Realm can be a good solution but it belongs to a company and its goodwill, I don't like that and the pod is very heavy in an application.

bizzibody profile image
Ian bradbury

I've been using Realm since I attempted to learn Core Data back in 2015/6. Core Data gave me such a headache that I ended up looking for something else. Realm was like a breath of fresh air and I've stuck with it since. But now that Mongo have bought Realm I'm a little worried about Realm's future (they're saying all the right things - but well they would wouldn't they)

Apparently Core Data has been much improved over the last year or so. Can anyone shine a light on improvements and why I might want to have another look?

midhetfatema94 profile image
Midhet Sulemani

I guess a lot of people used to use other forms of persistence in the app previously, for reasons I am not completely aware except for that Core Data felt unnecessarily complicated and intimidating. But since the time I have started using Core data, I feel like the initial code is a one time investment and it can be maintained and versioned easily. Maybe, these changes have come in the recent times, because I have less than 5 years of experience in iOS/Swift.

donnywals profile image
Donny Wals

Looking forward to reading your getting started with Core Data tutorial 😀