Posted in

Core Data Interview Questions: Quick Guide

Spread the love
Reading Time: 2 minutes

Core Data is one of the most commonly discussed topics in iOS developer interviews. Whether you’re preparing for junior, mid-level, or senior roles, this guide covers all Core Data interview questions—from basics to advanced concepts and real-world scenarios.

#Basic Level Core Data Questions

1. What is Core Data?

Core Data is Apple’s framework for managing the model layer of your app. It supports:

  • Local data persistence
  • Object graph management
  • Change tracking
  • Undo/redo functionality

2. What are the main components of Core Data?

  • NSManagedObjectModel
  • NSManagedObjectContext
  • NSPersistentStoreCoordinator
  • NSPersistentContainer (introduced in iOS 10)

3. What is an NSManagedObject?

It’s a class representing a single object stored in Core Data.
It maps directly to an entity in your .xcdatamodeld.

4. How do you save data in Core Data?

  1. Create an NSManagedObject.
  2. Set its properties.
  3. Call save() on the context:
try context.save()

5. How do you fetch data in Core Data?

Using NSFetchRequest, optionally with:

  • Predicates
  • SortDescriptors
  • Limits

#Intermediate Level Core Data Questions

6. What is an NSPersistentContainer?

A convenience wrapper that contains:

  • Model
  • Context
  • Store coordinator

It simplifies Core Data stack setup.

7. What is NSManagedObjectContext and why is it important?

It is a workspace/scratchpad where you:

  • Create objects
  • Modify objects
  • Track changes
  • Save or undo changes

8. What’s the difference between main context and background context?

  • Main context: Runs on main thread → use for UI-related tasks
  • Background context: Runs on background queue → use for heavy operations

9. What is a predicate in Core Data?

NSPredicate filters fetch results.
Example:

NSPredicate(format: "name == %@", "Alice")

10. What are relationships in Core Data?

Entities can have:

  • One-to-One
  • One-to-Many
  • Many-to-Many

Relationships also support delete rules.

#Advanced Level Core Data Questions

11. How is Core Data different from SQLite?

Core DataSQLite
Object graph managerSimple database
Supports faulting, undo, validationRaw SQL
Manages relationships automaticallyManual joins
Uses SQLite internally (optional)SQL only

Note: For Detailed Core Data vs Sqlite vs Realm comparison, check here.

12. What are merge policies?

Used to resolve conflicts when multiple contexts save changes.

Common merge policies:

  • mergeByPropertyObjectTrump
  • mergeByPropertyStoreTrump
  • overwrite
  • rollback

13. How do you handle concurrency in Core Data?

  • Use background contexts
  • Use perform or performAndWait
  • Avoid passing NSManagedObject instances across threads
  • Use object IDs instead

14. What types of persistent stores does Core Data support?

  • SQLite (default)
  • Binary
  • In-memory

15. What is faulting in Core Data?

Faulting is a lazy-loading mechanism:

  • Objects are placeholders until their properties are accessed
  • Saves memory and improves performance

16. What is Core Data migration?

When a data model changes, Core Data must migrate old data.

Types:

  • Lightweight Migration: Automatically handles simple changes
  • Heavy/Custom Migration: Requires mapping models

17. What is NSFetchedResultsController?

A controller that monitors Core Data objects and updates UI components—mostly used with UITableView and UICollectionView.

#Practical / Scenario-Based Core Data Questions

18. How to efficiently insert a large number of records?

  • Use background context
  • Disable undo manager
  • Save in batches (e.g., every 100 inserts)

19. What are some Core Data performance best practices?

  • Use faulting
  • Avoid large fetches
  • Use batch updates / batch deletes
  • Use indexing for frequently queried attributes

20. How do you test Core Data logic?

  • Use an in-memory store for unit tests
  • Mock NSManagedObjectContext
  • Isolate business logic

I'm a passionate iOS Developer with over 8 years of experience building high-quality iOS apps using Objective-C, Swift, and SwiftUI. I created iostutor.com to share practical tips, tutorials, and insights for developers of all levels.

When I’m not coding, I enjoy exploring new technologies and writing content — from technical guides to stories and poems — with the hope that it might help or inspire someone, somewhere.

Leave a Reply

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