After searching everywhere I found there is no properer comparison between SQLite, Realm, CoreData, UserDefaults, and JSON file.
You can find pros and cons easily but it's hard to know what to use.
I know the decision is totally dependent on the requirements. But still there must be a way to make decision.
Assuming the following cases, which options are best for individual and why?
Note: I am not talking about storing sensitive information here.
Feel free to add/update more relevant cases.
Here is Apple's quick overview: “Use Core Data to save your application's permanent data for offline use, to cache temporary data, and to add undo functionality to your app on a single device.” To give a bit more detail, CoreData is Apple's technology to save your structured data locally.
Core Data is unnecessary for random pieces of unrelated data, but it's a perfect fit for a large, relational data set. The defaults system is ideal for small, random pieces of unrelated data, such as settings or the user's preferences.
Though, CoreData also prevails over Realm in some ways. As you remember, the Apple framework offers a visual representation of the model in XCode. And many find the process of working with one-to-many and many-to-many relations in the Xcode model editor easier than using the LinkingObjects () function in Realm.
Core Data can use SQLite as its persistent store, but the framework itself is not a database. Core Data is not a database. Core Data is a framework for managing an object graph.
The most part of data storage implementation is just SQLite wrappers. The most common iOS implementations are SQLite, ORM, CoreData, Realm, Keychain.
Another part of implementations is just a simple text. For example, UserDefaults is just an XML file which you can edit using simple iOS API. But SQLite wrappers are more useful for performance reasons when you work with more than dozens of elements.
So, what about SQLite wrappers?
What about the summary?
SQLite (Wrapper, pure C) and Realm in our test have nearly the same performance. CoreData isn't good enough.
SQLite wrapper and Realm have enough good API.
The only SQLite wrapper is really thread-safe.
Available Options to save data in iOS.
User Default: Quicky persists a small amount of data.
Codable (NSCoder): for saving the custom object.
Keychain: Small bit of data securely.
SQLite: Persist large data but require query operation.
Core Data: Object-Oriented Database.
Realm: Faster and easier database solution.
CoreData, Sqlite & Realm store plain text in-store if you don't tell it to encrypt, you can use encryption in all to make it secure.
Saving user-watched history [Huge amount of data, Only insert, and delete operation] Coredata & Realm should be used.
Saving contact numbers [Max 1000 numbers, Need fast fetch, and continuous operation] Coredata & Realm should be used.
Saving simple GET API request [Use for caching] Codable, Coredata & Realm should be used. The response can be used for offline storage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With