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?
- Create an
NSManagedObject. - Set its properties.
- 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 Data | SQLite |
|---|---|
| Object graph manager | Simple database |
| Supports faulting, undo, validation | Raw SQL |
| Manages relationships automatically | Manual 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:
mergeByPropertyObjectTrumpmergeByPropertyStoreTrumpoverwriterollback
13. How do you handle concurrency in Core Data?
- Use background contexts
- Use
performorperformAndWait - Avoid passing
NSManagedObjectinstances 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
