Comparison of iOS databases: SQLite vs. Core Data vs. Realm

Source: Internet
Author: User

Comparison of iOS databases: SQLite vs. Core Data vs. Realm

If you want to develop a great application that can quickly run without bugs, you must carefully consider all aspects of your application. There is one thing you must solve: how to store and query big data, then you are likely to use the database. In most cases, the IOS database selects SQLite and Core Data, and a relatively new database Realm.

This article describes the advantages and disadvantages of each choice, and discusses how to convert to Realm if you have used SQLite or Core Data.

SQLite

SQLite is the most widely used database engine in the world and is still open-source. It implements a transaction database engine without configuration and service requirements. SQLite can be used on Mac OS-X, iOS, Android, Linux, and Windows.

Since it is developed using ANSI-C, it provides a simple and easy to use programming interface. SQLite is also a small, lightweight database that can be stored on a cross-platform disk file.

The reason why SQLite is so popular is:

  • Independent from servers
  • Zero Configuration
  • Secure Access under multiple processes and threads.
  • Use one or more columns containing special data types in a table to store data.

How to install JSON-supported SQLite 3.9.1 on Ubuntu 15.04

SQLite3 simple operation

Analysis on the combination of storage and data types in SQLite3

SQLite3 installation and basic operations

Simple Application of SQLite databases in Ubuntu 12.04

How to install SQLite in Ubuntu 12.04

Basics of SQLite Database

SQLite details: click here
SQLite: click here

Core Data

Core Data is the second largest IOS storage technology available to App developers. You need to manage and store Data based on Data types and Data volumes. SQLite and Core Data both have their own advantages and disadvantages. Core Data focuses more on objects than traditional table database methods. Using Core Data, you can store an Objective-C Class Object.

Although they are essentially different, Core data ::

  • More memory than SQLite.
  • More storage space than SQLite.
  • It is faster than SQLite in data retrieval.

Realm

Realm is a new technology. Realm is faster and more efficient than the database solution mentioned above. The new solution is called Realm, which is a cross-platform mobile database. It can be used in Objective-C and Swift, and is a database specially designed for iOS and Android.

The main advantages of Realm are:

  • Absolutely free
  • Quick and easy to use
  • No limits
  • It runs on its own persistence engine for speed and performance.

The best thing is that you can handle all your work through two lines of code. Realm is easier to install and run than SQLite and Core Data. In addition, database files can also be used on iOS and Android.

If you are designing a program that targets many users and has many records, you need to pay special attention to its scalability from the very beginning of the design. Realm is outstanding in this regard and allows you to quickly operate on a large amount of data.

To start using Realm, you only need a minimum iOS 8 or OS X 10.9 system. Earlier versions of the system do not support all-new simple solutions for local storage and databases.

Switch to Realm

If you have used Core Data and want to convert it to Realm, the process is simple. It takes a couple of hours for many developers to complete the process. Note that both Core Data and Realm process Data in the form of objects. Therefore, you only need to refactor the Core Data code and use Realm.

Realm has summarized the switching process. Here is my summary of it:

  • Remove the Core Data framework. Locate the part of your code that contains the Core Data code and then refactor it. They sum up a good way to help use each line of Core Data code to throw a compilation error.

  • Remove the Core Data installation code. The Core Data installation code must be included somewhere in your application. You must completely remove the Core Data. Realm is automatically configured immediately when you first access the Realm object. You can select the location where you want to store Realm data files, but you can still choose at runtime.

  • Migrate your model file. You can easily convert and manage sub-classes of objects to Realm. Realm manages attribute keywords internally to make class headers look smaller (you don't have to specify them yourself ). You can safely remove all NSNumber items because Realm supports simple numeric types (NSInteger and CGFloat ). However, Realm also has some limitations. Unlike the Data Objects of Core Data, which use NSManagedObjectID to determine the uniqueness of objects, Realm submits this to developers for management. Second, the current version of Realm cannot process object attributes that contain nil values. This is a small problem, but developers are expected to solve it in the next version.

  • Migrate your write operations. The storage operation of Realm is a little different from that of Core Data. You need to understand this problem. Once you add the Realm Data object to the Realm object, it cannot be modified. This ensures data consistency in different threads. To be able to modify attributes. These stored objects must be in the 'write' transaction.

  • Migrate your query so that your query can retrieve your data as needed. In Core Data, you need to write nearly 10 lines of code to get a file. But in Realm, only one row is required.

  • The migration user generates Data in the Core Data. You can reconnect to the Core Data framework in the application and use it to transmit Data to Realm. A simple solution for alternative user Data is to delete all the Core Data storage files and restart the application at the next startup.

The key is to keep the process simple when using the best technologies and tools. Once you have spent time building your effective process, don't let "new attraction" take you away. Make "new" a part of your process, and then let the time decide whether it is worthwhile.

IOS Database Comparison: SQLLite vs. Core Data vs. Realm

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.