Complete the code to create a new SwiftData model instance and save it.
let newItem = Item(name: "Sample") context.insert(newItem) try context.[1]()
In SwiftData, you call save() on the context to save changes like new items.
Complete the code to fetch all items from SwiftData context.
let request = FetchDescriptor<Item>() let items = try context.[1](request)
The fetch(_) method is used to get data matching a fetch descriptor in SwiftData.
Fix the error in the code to update an existing item and save changes.
item.name = "Updated" try context.[1]()
To save updates in SwiftData, you call save() on the context after changing properties.
Fill both blanks to delete an item from SwiftData and save the change.
context.[1](item) try context.[2]()
Use delete(_) to remove an item, then save() to persist the deletion.
Fill all three blanks to create a filtered fetch request for items with name longer than 5 characters.
let request = FetchDescriptor<Item>( predicate: #Predicate { \.name.[1] [2] [3] } )
Use count on the string property, then compare with > and the number 5 to filter items.