【发布时间】:2022-01-21 16:55:31
【问题描述】:
我想将@Published 变量的绑定从我的ObservableObject 传递给一个结构,以便可以在闭包内更改它的值。我不能让它工作。下面是我的代码的简化版本:
final class OnboardingStateController: ObservableObject {
@Published var shouldHide: Bool = false
func go() {
MyLogic.fooBar(
shouldHide: shouldHide // error appears here Cannot convert value of type 'Bool' to expected argument type 'Binding<Bool>'
)
}
}
struct MyLogic {
static func fooBar(shouldHide: Binding<Bool>) {
... SomeClass({ shouldHide.wrappedValue = true })
}
}
我该怎么做?
【问题讨论】: