Core Data in Swift
- 46Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
46 questions
- 1Core Data stores data in a SQL database but lets Swift code interact with it through an_____approach.
Hint
Think of the programming model built around objects and their properties.
Answer
object-oriented
Explanation
Core Data uses SQL behind the scenes while presenting an object-oriented interface, so developers do not need to write SQL statements for ordinary use.
- 2The central map in Core Data connects objects and their vars to tables and_____in a relational database.
Hint
Relational database tables are made up of columns and individual records.
Answer
rows
Explanation
Core Data maps object-oriented data to the tables and rows of its underlying relational database.
- 3In Xcode’s Core Data model editor, the objects that will be stored are represented as_____entities.
Hint
These are the named object types, such as Flight, Airport, and Airline.
Answer
Core Data
Explanation
The model editor defines entities such as Flight, Airport, and Airline, along with their attributes and relationships.
- 4Xcode generates the classes that represent the entities and their stored_____from the data model.
Hint
These are the properties associated with each object.
Answer
vars
Explanation
After entities and attributes are defined in the model, Xcode generates code for classes that represent them and their stored vars.
- 5Developers can add methods and computed vars to generated Core Data classes using_____
Hint
This Swift feature adds functionality to an existing type without changing its original definition.
Answer
extensions
Explanation
Extensions let developers add behavior and computed vars to the generated entity classes.
- 6The database model can define object_____graphically, such as linking a Flight to its Airport.
Hint
These express how one stored object is connected to another.
Answer
relationships
Explanation
The model editor supports graphical relationships between entities, in addition to defining their attributes.
- 7Core Data entity attributes are optional by default because a database object may be incomplete or_____
Hint
Consider what might happen if a record is damaged or only partly created.
Answer
corrupted
Explanation
The lecture explains that database values may be missing if an object was only partly created or the database was corrupted, so generated properties are optional by default.
- 8A Core Data property marked optional in the model is not necessarily a Swift_____
Hint
The same word is used for two different notions of optionality here.
Answer
Optional
Explanation
The model’s optional setting concerns whether a value may be absent in the database; the lecturer cautions that this is not the same as Swift Optional.
- 9The Core Data stack’s persistent container holds the database, while an NSManagedObjectContext provides the application's_____onto it.
Hint
It is the access point through which database operations are performed.
Answer
window
Explanation
The persistent container holds the Core Data database, and the managed object context is the window through which code accesses database objects.
- 10The context is needed when creating objects, fetching objects, and_____changes to the database.
Hint
This operation commits changes so they persist.
Answer
saving
Explanation
Core Data operations use the context, including creating objects, fetching them, and saving changes.
- 11When a new project is created with Core Data enabled, Xcode provides a blank data_____to define entities and attributes.
Hint
It is the file edited in Xcode’s graphical entity editor.
Answer
model
Explanation
Enabling Core Data creates a blank model that developers can use to define their database entities, attributes, and relationships.
- 12The Core Data setup places code that creates the persistent store in the_____
Hint
This setup location is distinct from the code that injects the context into views.
Answer
AppDelegate
Explanation
The generated Core Data stack in AppDelegate creates the persistent container and database store.
- 13The SceneDelegate obtains the managed object context from the persistent container and places it into SwiftUI’s_____
Hint
SwiftUI uses this mechanism to make values available to descendant views.
Answer
Environment
Explanation
The SceneDelegate retrieves the context and passes it through the Environment so SwiftUI views can access the database.
- 14A sheet or popover creates a new view environment, so the managed object context should be_____into it.
Hint
The new presentation needs access to the same database context as its parent.
Answer
passed
Explanation
Unlike views nested in a parent’s body, a sheet or popover has its own environment. The context must be explicitly passed into that environment.
- 15Saving a context can fail, so the call to context.save() must be handled with Swift’s_____mechanism.
Hint
This keyword is used when calling a throwing function.
Answer
try
Explanation
The save operation can throw, for example if storage is unavailable or another error occurs, so it must be called with try or another error-handling form.
- 16Core Data’s optional CloudKit integration can mirror database contents to_____so they are available across a user’s devices.
Hint
It is Apple’s cloud service for synchronizing data across devices.
Answer
iCloud
Explanation
When CloudKit support is enabled, Core Data data can be mirrored to iCloud and made available on the user’s devices.
- 17An NSFetchRequest specifies the entity to fetch and can use a predicate to select records and sort descriptors to control their_____
Hint
These descriptors determine how returned results are arranged.
Answer
order
Explanation
A fetch request identifies the entity and can specify both filtering criteria and result ordering through sort descriptors.
- 18An NSPredicate describes the_____that fetched objects must satisfy.
Hint
It determines which records should be included in the results.
Answer
criteria
Explanation
A predicate defines which database objects match a request, such as flights arriving before now from a particular origin.
- 19In a predicate format, the placeholder_____
%@is paired with the correspondingvalues.Hint
These are supplied after the format string to fill in the requested values.
Answer
arguments
Explanation
Predicate formats use placeholders such as
%@, followed by arguments that provide the values to compare against. - 20The predicate_____
TRUEPREDICATEmatches every object, making it useful when fetchingairports.Hint
The predicate evaluates to true for every record.
Answer
all
Explanation
TRUEPREDICATE is always true, so it can be used to fetch all objects of an entity, such as all airports.
- 21An NSSortDescriptor specifies a property to sort by and whether the ordering is ascending or_____
Hint
This is the reverse of ascending order.
Answer
descending
Explanation
A sort descriptor identifies the property used for sorting and whether results should be ordered ascending or descending.
- 22A FetchRequest’s sort descriptors let the database perform sorting efficiently on the database_____
Hint
This contrasts with sorting the results only after they reach the application.
Answer
side
Explanation
The lecture notes that SQL databases are good at sorting, so sort descriptors allow ordering to happen on the database side.
- 23The context’s fetch method may throw; using_____
try?makes a failed fetch produceHint
This result differs from a successful fetch with no matching records.
Answer
nil
Explanation
With try?, a fetch error becomes nil. A successful fetch with no matches instead returns an empty array.
- 24A successful fetch with no matching records returns an empty_____rather than nil.
Hint
A successful fetch returns a collection of matching objects, even when there are none.
Answer
Array
Explanation
An empty Array indicates the fetch succeeded but found no matches; nil from try? indicates that the fetch failed.
- 25A Core Data entity’s generated objects are ObservableObjects, so an individual Flight can be presented in SwiftUI using_____
Hint
This property wrapper observes a single reference-type model object in a view.
Answer
@ObservedObject
Explanation
Core Data objects such as Flight, Airport, and Airline are ObservableObjects and can be observed by SwiftUI views.
- 26The lecture notes that an observed Core Data object may require an explicit_____
objectWillChange.send()call after its values areHint
The notification tells observing views that the object is about to update.
Answer
changed
Explanation
The lecturer found that observed Core Data objects did not always signal changes automatically, so objectWillChange.send() could be called explicitly.
- 27SwiftUI’s @FetchRequest wraps results in a_____Results collection rather than an ordinary Array.
Hint
The type name begins with the past-tense form of “fetch.”
Answer
Fetched
Explanation
The property wrapper provides a FetchedResults collection containing the requested Core Data objects.
- 28FetchedResults is a Collection, so it can be supplied to SwiftUI’s_____view for presenting repeated items.
Hint
This SwiftUI container creates content for each element in a collection.
Answer
ForEach
Explanation
FetchedResults conforms to Collection, making it suitable as the collection iterated over by ForEach.
- 29Unlike a one-time fetch, @FetchRequest acts like a standing_____that tracks database changes.
Hint
It continually checks which objects meet the stated criteria.
Answer
query
Explanation
A FetchRequest property wrapper continually reflects objects that match its request, rather than returning only a one-time snapshot.
- 30When database changes alter which objects match a FetchRequest, SwiftUI updates the results and redraws the_____
Hint
This is the visible interface presented to the user.
Answer
UI
Explanation
FetchRequest keeps the view’s results synchronized with matching database changes, causing the UI to update.
- 31A FetchedResults collection can be converted to an Array by using the Array_____
Hint
This is the construction operation that accepts a Collection.
Answer
initializer
Explanation
Because FetchedResults is a Collection, it can be passed to the Array initializer to produce an Array.
- 32A Flight’s destination and origin properties each refer to one Airport, so each is a_____relationship.
Hint
The relationship points from one flight to a single airport.
Answer
To One
Explanation
Each Flight has one destination Airport and one origin Airport, making those Flight-side relationships To One.
- 33An Airport can have multiple arriving Flights, so its flightsTo relationship is configured as_____
Hint
The airport is connected to a collection of flights rather than a single flight.
Answer
To Many
Explanation
Many Flight objects can share the same destination Airport, so the Airport’s flightsTo relationship is To Many.
- 34When a Flight’s origin is set to an Airport, Core Data automatically updates the Airport’s corresponding_____relationship.
Hint
It is the Airport-side relationship for flights departing from that airport.
Answer
flightsFrom
Explanation
Core Data maintains both sides of a configured relationship, so assigning a Flight’s origin also updates the Airport’s flightsFrom collection.
- 35When a Flight’s destination is set, Core Data automatically adds it to the destination Airport’s_____relationship.
Hint
It is the Airport-side relationship for flights arriving there.
Answer
flightsTo
Explanation
The inverse relationship is maintained automatically: setting a Flight’s destination updates the Airport’s flightsTo collection.
- 36The generated Airport relationship may be an Objective-C NSSet of Any, so an extension can expose a Swift_____of Flight instead.
Hint
This native Swift collection represents unique elements.
Answer
Set
Explanation
The lecture uses computed properties to convert the Objective-C NSSet relationship into a typed Swift Set of Flight.
- 37A computed relationship property can return an empty Set when the underlying database relationship is_____
Hint
This is the absence value the computed property is designed to guard against.
Answer
nil
Explanation
The computed property hides optionality by returning an empty Set when the stored relationship value is nil.
- 38Flight, Airport, and Airline inherit from_____
Hint
This is the Core Data superclass used when an array may contain different entity types.
Answer
NSManagedObject
Explanation
Using NSManagedObject as a common superclass allows values from different Core Data entity classes to be stored in one array.
- 39In the flight-search predicate, destination is always included, while origin and airline criteria are added only when those values are_____
Hint
Optional filters are included only when the user has selected them.
Answer
present
Explanation
The predicate is constructed programmatically: it always filters by destination and conditionally adds origin and airline conditions.
- 40The demo first retrieves FlightAware data, stores it in Core Data, and then builds the UI by reading from the_____
Hint
After loading, the interface no longer depends directly on the network response.
Answer
database
Explanation
The application loads FlightAware data into Core Data and uses the database as the source of data for the UI.
- 41Core Data objects know the managed object context they came from, allowing an instance method to access that context without always_____it as an argument.
Hint
This avoids repeatedly supplying the same context to instance methods.
Answer
passing
Explanation
An object retrieved from Core Data can access its managedObjectContext, so code can use that context for related database operations.
- 42When a FlightAware response arrives, the app can look up a Flight by its ident, then update or_____the matching database object.
Hint
If no record is found, a new object is needed.
Answer
create
Explanation
The update workflow searches by ident; it updates the existing Flight if found or creates one when no matching Flight exists.
- 43Airport and Airline lookup helpers first search the database by a unique code and create a record if none is_____
Hint
The helper reuses existing records rather than duplicating them.
Answer
found
Explanation
The withICAO and with-code helpers fetch an existing object by its code, creating one only when the search returns no match.
- 44When a new Airport is created before its FlightAware details arrive, its identifier can be set immediately while other information is filled in_____
Hint
The network response arrives later, after the initial object has been returned.
Answer
asynchronously
Explanation
The Airport can initially contain its ICAO, while FlightAware information such as coordinates arrives later and updates the database asynchronously.
- 45For a Core Data query, predicates and sort descriptors must refer to the database_____names, even when Swift extensions expose cleaner computed properties.
Hint
These are the stored model properties used by the database query.
Answer
field
Explanation
Fetch predicates and sort descriptors operate on fields in the data model, so renamed or computed Swift properties cannot replace the stored model names in the query.
- 46If a context save fails, a do-catch block can catch the error and inspect its_____description.
Hint
This error description is intended to be presented or interpreted in a user’s locale.
Answer
localized
Explanation
The demo shows catching a save error and printing its localizedDescription to help identify the failure.

Ask anything
We've read this whole study set, so questions about it get the best answers.