我正在尝试优化我的代码以最小化不必要信息的下载大小。
我的目标是将 testData 数组中的项目链接到另一个结构中调用方法。
下面是一个例子:
struct Recipe: Identifiable, Hashable, Codable {
@DocumentID var id: String? = UUID().uuidString
var title: String
var description: String
var imageName: String
}
let testData = [
Recipe(title: "Recipe1", description: "Description1", imageName: "Image1"
Recipe(title: "Recipe2", description: "Description2", imageName: "Image2"
Recipe(title: "Recipe3", description: "Description3", imageName: "Image3"
]
// Then another struct, which needs to be linked to members of the array above
// Code below is incorrect, will not work
struct CommentSection {
var recipe: Recipe // …Run Code Online (Sandbox Code Playgroud)