iOS Development iOS Data Persistence 1 — Questions and Answers
Question 1: Which iOS framework provides a key-value store for small amounts of persistent data?
- UserDefaults (Correct answer)
- Core Data
- Keychain
- CloudKit
Correct answer: UserDefaults
UserDefaults provides a simple interface for storing small pieces of data, such as user preferences, using key-value pairs.
Question 2: Where should sensitive data like passwords be stored on iOS?
- Keychain (Correct answer)
- UserDefaults
- Core Data
- NSCache
Correct answer: Keychain
The iOS Keychain provides encrypted, hardware-backed storage specifically designed for sensitive credentials and tokens.
Question 3: What is Core Data's primary role in an iOS app?
- Object graph management and persistence to SQLite or other stores (Correct answer)
- Syncing data in real time across devices
- Encrypting data stored on disk
- Caching network responses
Correct answer: Object graph management and persistence to SQLite or other stores
Core Data manages the model layer of an app as an object graph, persisting it to a SQLite store (by default) or in memory.
Question 4: Which class is the central object in a Core Data stack?
- NSPersistentContainer (Correct answer)
- NSManagedObjectContext
- NSFetchRequest
- NSPersistentStore
Correct answer: NSPersistentContainer
`NSPersistentContainer` encapsulates the Core Data stack setup, providing the managed object model, context, and persistent store coordinator.
Question 5: What is the purpose of NSManagedObjectContext in Core Data?
- Acts as a scratchpad for creating, fetching, and saving managed objects (Correct answer)
- Defines the data schema for the persistent store
- Handles migration between model versions
- Encrypts data before writing to disk
Correct answer: Acts as a scratchpad for creating, fetching, and saving managed objects
NSManagedObjectContext is an in-memory scratchpad where you work with managed objects; calling `save()` persists changes to the store.
Question 6: Which iOS API is used to store small files in the app's sandboxed file system?
- FileManager (Correct answer)
- URLSession
- NSCache
- CoreFoundation
Correct answer: FileManager
FileManager provides an interface to the file system, allowing apps to create, read, write, and delete files within their sandbox.
Which iOS framework provides a key-value store for small amounts of persistent data?