To use SwiftData you basically need these three things and to read the documentation.
Add the macro @Model
Add .modelContainer to the view
Add the @Environment(.modelContext) private var context
Finally, in SwiftData you can use FetchDescriptor with a Predicate to fetch and sort.
The following example is in the SwiftData example provided by Apple.
@Model
class Recipe {
@Attribute(.unique) var name: String
var summary: String?
var ingredients: [Ingredient]
}
So, var ingredients would be an array of elements that are of data type Ingredient. So make that. Example:
@Model
class Ingredients{
var name: String
var amount: String
var somethingElse: ThatType
}
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags: