[英]SwiftUI toggle() function on Published values stopped triggering didSet with Swift 5.2
I have just updated my Xcode to 11.4 from 11.3 and my project written in SwiftUI started to behave differently.我刚刚将我的 Xcode 从 11.3 更新到 11.4,我用 SwiftUI 编写的项目开始出现不同的行为。 I used to call
toggle()
function for boolean values and it used to trigger didSet
property observer, however, it is not working any more.我曾经为布尔值调用
toggle()
函数,它用于触发didSet
属性观察器,但是,它不再起作用了。
Let' say we have a State
property called isSettingOn
.假设我们有一个名为
isSettingOn
的State
属性。 I used to call this:我曾经这样称呼:
isSettingOn.toggle()
which was triggering didSet
observer of the property.这是触发属性的
didSet
观察者。 Now, only if I call this:现在,只有当我调用它时:
isSettingOn = true
it is working.这是工作。
My projects are all based on this behaviour and now this change basically broke everything.我的项目都是基于这种行为,现在这种变化基本上打破了一切。 Does anyone know if I am actually doing anything wrong here?
有谁知道我在这里是否真的做错了什么?
Edit:编辑:
Demo code added:添加的演示代码:
struct ContentView: View {
@State var isSettingOn: Bool = true {
didSet {
print("didSet isSettingOn")
}
}
var body: some View {
Button(action: {
self.isSettingOn = true // will trigger didSet
self.isSettingOn.toggle() // won't trigger didSet
}) {
Text("Toggle isSettingOn")
}
}
}
这是Xcode 11.4 and 11.4.1
中的一个错误,它在Xcode 11.5 (Beta)
和Swift 5.2.4
得到修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.