SwiftData - Load the data into Apps

I am developing "Tasty Recipes" app. I want to load all data related to this app such "Recipe Category", "Recipes List", "Recipes Inscredient", "Preparation Methods" and so on. How can I load and store all data using SwiftData. User is going to use these data. They will update few things like "Favourite Recipes", "Rating". How can I do this.

To use SwiftData you basically need these three things and to read the documentation.

  1. Add the macro @Model
  2. Add .modelContainer to the view
  3. Add the @Environment(.modelContext) private var context
  4. 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
}

Ingredients should be Ingredient

@Model
class Ingredient {
    var name: String
    var amount: String
    var somethingElse: ThatType
}
SwiftData - Load the data into Apps
 
 
Q