CRUD Operation with CoreData

Updated 29 October 2021

Save

Hi guys, Today we will learn about how to implement CRUD Operation with CoreData in an ios application.

Before starting to code first we need to know what is CRUD Operation with CoreData  –

Core Data is an object graph and persistence framework provided by Apple in the iOS and macOS operating system. It allows data organized by the relation entity-attribute model to be serialized into XML, binary, or SQLite stores.

Data Create   –

  1. create the context from persistent container
  2. create an entity with a user
  3. set value for the records for each key

Example –

Update Data in Coredata-

  1. prepare the request with a predicate for the entity.
  2. Fetch record and set new value with key
  3. save context

Example –

Delete Data in CoreData-

  1. Prepare the request with a predicate for the entity
  2. Fetch record and which we want to delete
  3. make context.delete call

Example –

let’s take an example –

step 1:  create a new project, and select use the core data option.

step 2:  create a file for core data,

  1. click on CoreData.xcdatamodeld option
  2. Click on the Add Entity option
  3. And add your data which you need to save in core data

step 3: it looks like this

  1. Click on the plus icon
  2. enter your data name which you want to store.

code of the example –  create a file for the alert box  i.e ButtonBar.swift class

2. create a viewController class

I am attaching some screen of my code for a better understanding

Conclusion –

In this blog, we have discussed how to save, update, create  and delete the data in the database by using The CRUD operation with core data

I hope this blog will help you in getting some basic knowledge about the CRUD operation with core data.

Thanks for reading!

author
. . .

Leave a Comment

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


Be the first to comment.

Start a Project


    Message Sent!

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

    Back to Home