Demo Core Data For Beginners Swift
- Nheng Vanchhay
- Aug 26, 2021
- 1 min read
Core Data is an object graph and persistence framework provided by Apple in the macOS and iOS operating systems. It was introduced in Mac OS X 10.4 Tiger and iOS with iPhone SDK 3.0. It allows data organized by the relational entity–attribute model to be serialized into XML, binary, or SQLite stores.
Core Data:
Don’t have Data Constraints,if required need to implement by business logic.
Operates on in memory.(data needs to be loaded from disk to memory)
Need to load entire data if we need to drop table or update.
Fast in terms of record creation.(saving them may be time consuming

Core Data Demo


Config Entity Name In App Delegate

Create Records to Core Data
The process of adding the records to Core Data has following tasks
Refer to persistentContainer from appdelegate
Create the context from persistentContainer
Create an entity with User
Create new record with this User Entity
Set values for the records for each key
decalare global in vc


Retrieve Data
The process of fetching the saved data is very easy as well.

Update Data
For update record first we have to fetch/Retrieve data with predicate as same as above Retrieve data process.

Delete Data
For delete record first we have to find object which we want to delete by fetchRequest.

All Well Done. I hope you get what you want !!!
Get full code here: https://gitlab.com/vanchaynheng168/ios-note



Comments