Xcode 11.4 Beta, Swift 5.2: Compiler error for binding

Using Xcode 11.4 and Swift 5.2 beta with my project.


3 of 10 Bindings I use I a SwiftUI project are now generating errors during compilation


Return from initializer without initializing all stored properties


Dont for the life of me understand why.


I assume a compiler bug?

Accepted Reply

Yes, that definitely works as a workaround.


Thank you. Going to mark it as a 'correct' answer

Replies

Could you show the full code (at least this where error occurs), so that we can try reproduce and check if there's a compiler bug?

I suspect it's more a stricter error detection from compiler (this area is said to have improved in 11.4) and you should make sure all stored properties are initialized.


Anyway, that's a beta, hope you don't use it for production code.

It happens to my project too, but does not reproduce in a simple app. Could you examine the compiler logic regarding @Binding var?

How do you want me to examine the compiler logic ??? I've no access to compiler's code (I'm not from Apple).


But if you post the code and explain condiitions where you see the problem, may be it is possible to further investigate.

What Claude31 said but also…

If you have code that compiles in Xcode 11.3 but fails to compile in Xcode 11.4 beta, you should file a bug about that. Swift is intended to be source compatible from release to release. There are some cases where the code is broken and it’s not possible for the new compiler to maintain compatibility, but all such situations warrant investigation.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I believe I'm having the same issue with my project, and have been able to isolate it to a specific combination involving a protocol with an associated type and initializer requirement, another generic type that uses that protocol and has additional requirement on the associated type, and a typealias that combines the two. I've filed a Swift bug with a demo project: https://bugs.swift.org/browse/SR-12165.

Yeah Im getting the Same error from a @Binding var, code did work in 11.3 but doesnt in 11.4 beta,


here is my code that doesnt work for example case:

struct CodeEditorView: View {
    
    // Variables
    @Binding var text: String // What is possibly causing the error
    var isActive: Bool? = true
    var hideStatusBar: Bool? = false
    
     // Error wants me to initialize text (aka the binding) 
     //but its impossibly to initialize a Binding based on how theywork
    /*init(text: String = "", isActive: Bool? = true, hideStatusBar: Bool? = false) {
        self.text = text
        self.isActive = isActive
        self.hideStatusBar = hideStatusBar
    }*/
    
    var body: some View {
        VStack {
            HStack {
                CodeTextView(text: $text, isEnabled: self.isActive)
            }.padding(.bottom, !hideStatusBar! ? -7 : 0)
            if (!hideStatusBar!) {
                CodeEditorStatusBarView()
            }
        }.padding(.top, -20)
    }
}

Unfortuantly no cant post here, removing just the problem classes to a seperate project compiles fine.

Thanks, have posted a bug report. FB7589564


Got caught up and didnt get back here again, and, quite honestly, I'm embarassed to let anyone see the code.


Compile bug still occurs in Xcode 11.4 beta 2.


One of the 2 compilation errors disappears if I make a change to a file that references it.

Where you able to create a test project that showed it, or did you submit a bug report with whatever project your working on?

Certainly sounds similar. Thank you for posting that bug report and making a small testcase. Have you also filed it as a bug against Xcode using Feedback Assistant? If not probably worth doing.


I'd have gone for higher than medium priority, just because I can't do anything with that code while getting that error 🙂

Thanks for the feed back, but totally useless for the forum as you give no information at all.


Good luck by yourself so.

Claude31 the compiler in Swift 5.2 is reacting to the code base differently that it did in 5.1


I could post code snippets that show that the binding is being initialised and where its declared but it isn't going to allow you to help. This appears to be a compiler bug, and as other replies to this thread show, I am not the only one affected.


I copied some of the exact code out into a seperate project and it compiled fine (a SwiftUI view, with the Binding, and where the @State is set). It is something that is coming up as a cummulation of the compile process.


However Vlas above has managed to create a very specific set of code that does demonstrate the issue.

Many thanks for the explanation.

Also happening in Xcode 11.4 Beta 2 unfortunately. We'll have to wait another 2 weeks to, maybe, have a fix, but the problem doesn't figure in the releases notes. Anybody found a workaround?

Until it gets fixed...

Workaround; make your binding initialization explicit, this way:

struct MyView: View {
     @Binding var variable: Bool
     var body: some View {
          ...
     }

     init(variable binding: Binding<Bool>) {
          self._variable = binding
     }
}


That should work. Hope I helped.