Search Your Question

How you can add column in entity in core data that can be also added in next release?

Ans : When you initialise a Core Data stack, one of the steps involved is adding a store to the persistent store coordinator. When you encounter this step, Core Data does a few things prior to adding the store to the coordinator. First, Core Data analyzes the store’s model version. Next, it compares this version to the coordinator’s configured data model. If the store’s model version and the coordinator’s model version don’t match, Core Data will perform a migration, when enabled.

Note: If migrations aren’t enabled, and the store is incompatible with the model, Core Data will simply not attach the store to the coordinator and specify an error with an appropriate reason code.

Migrations happen in three steps:
  1. Core Data copies over all the objects from one data store to the next. 
  2. Core Data connects and relates all the objects according to the relationship mapping. 
  3. Enforce any data validations in the destination model. Core Data disables destination model validations during the data copy.
Database Migration : 

Lightweight Migration
Manual Migration
Custom Manual Migration
Fully Manual Migration

Setting for Lightweight Migration: 

NSMigratePersistentStoresAutomaticallyOption: true
NSInferMappingModelAutomaticallyOption: true


Coredata Migration Tutorial : RayWanderLich


What is Core Data Stacks?

Ans : Core Data is Apple’s object graph management and persistency framework.

Core Data Stack
Core Data Stack


  1. Managed Object
  2. Managed Object Context
  3. Managed Object Model
  4. Persistent Store Coordinator

  1. NSManagedObject’s are the model objects exposed by Core Data.
  2. NSManagedObjectModel is a database schema that describes the application’s entities. It defines the structure of the managed objects.
  3. NSPersistentStoreCoordinator associates persistent storage and managed object model. It lends itself to mapping the data from the storage, say SQLite data base rows, into the object model. It is a task of high complexity and is often taken for granted when working with Core Data.What is more, the persistent coordinator is used by the managed object context when it comes to saving or fetching objects.
  4. NSManagedObjectContext controls the life cycle of the managed objects and provides operations to create, save and fetch them. You can think of the managed object context as a scratch pad with a group of managed objects.

Starting from iOS 10, NSPersistentContainer is responsible for creation and management of the Core Data stack.
NSPersistentContainer exposes a managed object model, a managed object context and a persistent store coordinator as well as provides many convenience methods when working them, especially when it comes to multithreaded applications.



What is delete rule in Core Data?

Ans : In our database, there may be multiple entities. One entity is connected with another entity in relationship. So deleting one data from one entity may have impact on another entity data depends on relationship or delete rule.

There are 4 delete rules :

  1. No Action
  2. Nullify
  3. Cascade
  4. Deny
Let's take example having one department entity and it is connected to employee entity with relationship as one-to-many. Employee to department entity relationship is one-to-one.

1. No Action : When No Action delete rule is set to relationship, then there will be no impact of deleting record from one entity. If we delete record from department connected to multiple employees, then there be no impact on employee entity. Employee assume that it has still relation with deleted department.

2. Nullify : If delete rule is set to Nullify to the relationship then the destination of the relationship gets nullify.  In our case, if department is deleted, then relationship between employee and department gets nullify. This is default delete rule.

3. Cascade Rule : If we delete department, then its related employees will be deleted if this delete rule is set. This rue is only used when data model has more dependency. 

4. Deny Delete Rule : This is opposite of Cascade Rule. If we set this rule, and we try to delete department which is connected to any of employee, then we are not allowed to delete department.

Depends on project requirement, we can set delete rule.


What is lazy loading?

Ans :  Lazy Loading Images is a technique to resolve loading image from the web. The thing is that, I need to display images directly from the web in UIImageView or any other control. 

For this, if you simply try to set the image using in-built setImage method then your application gets stuck while loading image from the web. To overcome this issue, there is a technique generally known as Lazy Loading Image. The thing actually happening in lazy loading is that the task of image loading from web is performed in background and at that time a temporary placeholder image is displayed in the control. When the actual image is fully loaded from the web, it is replaced with the placeholder image and you get your actual image on the control without having stuck interface.

You can use third party library to load image :  SDWebImage

Try to make own coding for loading image from URL and Save in cache and display in imageView.



What is apple enterprise account?

Ans : 

To Develop and Distribute app, there are two types of licence available.

1. Apple Developer
2. Apple Developer Enterprise

Difference : 



Source : LeoLearning