How can I get access to an instance of an array and change its element?

Viewed 15

Model

import Foundation

struct Recipe: Identifiable {
    var id = UUID()
    var cakeName: String
    var madeWith: String
}    

ViewModel

import Foundation

class RcipeModels: ObservableObject {  

    @Published var Recipes = [Recipe]()
    
    init() {
        Recipes.append(Recipe(cakeName: "Cake1", madeWith: "Pineapple"))
        Recipes.append(Recipe(cakeName: "Cake2", madeWith: "Chocolate"))
        Recipes.append(Recipe(cakeName: "Cake3", madeWith: "Honey"))
    }
}
0 Answers
Related