【发布时间】:2020-01-15 05:59:47
【问题描述】:
struct FinanceOutput: View {
@Binding var price: Double
@Binding var down: Double
@Binding var apr: Double
private var rate: Double = 0.0
init(price: Binding<Double>, down:Binding<Double>, apr:Binding<Double>, of rate: Double ) {
self._price = price
self._down = down
self._apr = apr
self.rate = rate
}
以上是我的代码,我确实在另一个视图中正确定义了@Binding 变量——使用@State。
我要做的是在等式中使用“率”来定义“apr/12”。我想我以前在早期版本的 Xcode 中解决了这个问题,但现在我得到的只是:“不能在属性初始化程序中使用实例成员 'apr';属性初始化程序在 'self' 可用之前运行。” 我知道我正在使用 Binding 类型,但即使我使用 Double() 更改类型,我仍然会收到错误。任何帮助,将不胜感激。
【问题讨论】:
-
提供的代码快照在我身边正确编译。请显示产生上述错误的代码。
标签: binding initialization swiftui