0
0
iOS Swiftmobile~5 mins

CRUD operations with SwiftData in iOS Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does CRUD stand for in app development?
CRUD stands for Create, Read, Update, and Delete. These are the four basic operations to manage data in an app.
Click to reveal answer
beginner
How do you create a new object in SwiftData?
You create a new object by initializing your model and then saving the context. For example, use @Model to define data and then call context.insert(newObject) followed by context.save().
Click to reveal answer
beginner
How do you fetch data using SwiftData?
Use a @Query property wrapper to fetch data. It automatically keeps your UI updated when data changes. For example, @Query var items: [Item] fetches all Item objects.
Click to reveal answer
intermediate
How do you update an existing object in SwiftData?
To update, change the properties of the fetched object and then save the context. SwiftData tracks changes automatically, so just call context.save() after editing.
Click to reveal answer
beginner
What is the correct way to delete an object in SwiftData?
Call context.delete(object) on the object you want to remove, then save the context with context.save(). This removes the object from the database.
Click to reveal answer
Which SwiftData property wrapper is used to fetch data reactively?
A@Query
B@State
C@Published
D@ObservedObject
What must you do after creating or modifying data in SwiftData to save changes?
ACall context.save()
BRestart the app
CCall context.fetch()
DNothing, changes save automatically
How do you delete an object from SwiftData?
ASet object to nil
BRemove the object from an array
Ccontext.delete(object) then context.save()
DCall object.remove()
Which CRUD operation involves changing properties of an existing object?
ADelete
BCreate
CRead
DUpdate
What is the purpose of the @Model attribute in SwiftData?
AFetches data from the database
BDefines a data model class
CDeletes data
DUpdates UI state
Explain the steps to create and save a new data object using SwiftData.
Think about how you add a new item to a list and save it.
You got /4 concepts.
    Describe how SwiftData helps keep your app UI updated when data changes.
    Imagine your app list changes automatically when you add or remove items.
    You got /3 concepts.