我这里有这个代码:
struct CheckoutView: View {
var itemInfoList: [itemInfo]
@State private var mutableItemInfoList: [itemInfo] = []
init(itemInfoList: [itemInfo]) {
self.itemInfoList = itemInfoList
self.mutableItemInfoList = itemInfoList
}
var body: some View {
ForEach(itemInfoList, id: \.self) { newItem in
Button(action: {
newItem.size = selectedSizesString
// problematic line
}) {
Text("Print Selected Sizes")
}
.alert(isPresented: $showingAlert) {
Alert(
title: Text("Selected Sizes"),
message: Text(selectedSizesString),
dismissButton: .default(Text("OK"))
)
}
}
}
}
struct itemInfo: Hashable {
var item: Item
var size: String
var comment: String
}
我正在尝试编辑每个项目内部的尺寸属性,但出现此错误:>
Cannot assign to property: 'newItem' is a 'let' constant
我不确定我做错了什么,我最好的猜测是
item
在ForEach
循环内。
像这样:
ForEach($items) { $item in