SQLite in Swift

Save

Nows-a days offline mode is a very common feature in app development. Every developer wants to run minimum app functionality without internet and device connect with internet all data automatically sync on remote DB. CoreData, SQLite, Firebase, etc. is handling offline functionality. Today we discuss about SQLite using swift.

What is SQLite?

SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. SQLite is the most used database engine in the world. It is built into all mobile phones and most computers and comes bundled inside countless other applications that people use every day.
Source: https://www.sqlite.org/

Let’s implement SQLite in swift for offline applications.

In this example, we will use the FMDatabase library to access SQLite.

Swift version: 5.2
iOS version: 14
Xcode: 12.0

First Create a project from Xcode.

File ▸ New ▸ Project…. Choose the iOS ▸ Application ▸ Single View App template and create a new project.

Step 1: First copy .sqlite file from FileManager to application.

Note: Make sure .sqlite already added on your project.
Step 2: Now create a DBHelper class, where we create all the oparations.

Step 3: Now We will create Insert update,delete and select oprations.
For Insert:

For Update value in the DB:

To delete Row form the table:

Now get all the row from the table:

Step 4: Now we call the function that we already created.

SQLite in Swift

I hope this code will help you better to understand SQLite in Swift. If you feel any doubt or query please comment below.

Thanks for the read this blog and if you want to visit my other blog click here.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

Webkul is a truly trusted and supported IT Company to develop business ideas for e-commerce. They provide professional support after deploying the solution to production and be responsible to act for fixing the reported issues or system errors. We highly encourage to deal with Webkul for business development.

Hussein Zawia

Hussein Zawia

Co-founder, 24Dokan

Talk to Sales

Global

Live Chat
Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home