我在一个类的 ContentView 中创建一个对象并将其传递给一个函数
@StateObject var portfolio = Portfolio()
...
///Cannot pass immutable value as inout argument: 'portfolio' is a get-only property
setCoin(portfolio: &portfolio, currencyList: currencyList, currency: currency, quantity: quantity)
...
func setCoin(portfolio:inout Portfolio, currencyList: [String : Int], currency: String, quantity: String){
for coin in portfolio.coins{
if coin.name == currency{
//Cannot assign to property: 'coin' is a 'let' constant
coin.quantity = Double(quantity)
portfolio.portfolioList.append(coin)
}
}
}
portfolio.coins 是从 JSON 解码中获得的对象数组。我正在尝试添加一个数量变量,该变量是用户输入以在视图中使用。