0

I have just updated my Xcode to 11.4 from 11.3 and my project written in SwiftUI started to behave differently. I used to call toggle() function for boolean values and it used to trigger didSet property observer, however, it is not working any more.

Let' say we have a State property called isSettingOn. I used to call this:

isSettingOn.toggle()

which was triggering didSet observer of the property. 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")
        }
    }
}
Cuneyt
  • 931
  • 5
  • 11
  • Works fine here. Would you provide demo code? – Asperi Mar 29 '20 at 04:47
  • Thanks @Asperi, I have updated my question with the sample code. Also, I have realised that the first issue (view not being updated) was related to the second issue I mentioned (didSet not being triggered) hence I also updated the question content. – Cuneyt Mar 29 '20 at 08:24
  • try this, it works! https://stackoverflow.com/a/59391476/8457280 – Chris Mar 30 '20 at 15:41
  • Looks like a bug that will be fixed in next Swift release. See https://github.com/apple/swift/pull/29931 – Monica Granbois Apr 17 '20 at 17:45
  • Thank you guys for your comments, I have posted an answer that this is fixed in Xcode 11.5. – Cuneyt May 18 '20 at 22:48

1 Answers1

0

This was a bug in Xcode 11.4 and 11.4.1 and it was fixed in Xcode 11.5 (Beta) with Swift 5.2.4.

Cuneyt
  • 931
  • 5
  • 11