我想更新和使用picker、textfield和get price函数中的容器成员.
struct PropertyContainer: Equatable {
static func == (lhs: PropertyContainer, rhs: PropertyContainer) -> Bool {
return lhs.fromQty == rhs.fromQty && lhs.fromCurrency == rhs.fromCurrency && lhs.toCurrency == rhs.toCurrency && lhs.toQty == rhs.toQty
}
@State var toQty: Double = 1.0
@State var toCurrency: String = "ETH"
@State var fromQty: Double = 1.0
@State var fromCurrency: String = "BTC"
}
struct ContentView: View {
@State private var propertyContainer = PropertyContainer()
在文本字段和 Select 器中使用容器的成员
.task(id: propertyContainer) {
do {
price = try await listMaker.getPrice(fromCurrency: propertyContainer.fromCurrency, fromQty: propertyContainer.fromQty, toCurrency: propertyContainer.toCurrency, toQty: propertyContainer.toQty, type: "Fixed")
print(propertyContainer.fromCurrency)
} catch {
print("Error")
}
}