Binding and 'Return from initializer without initializing all stored properties'

I am trying to use TextEditor
my code runs well
until I add the

@Binding var isLoggedIn: Bool

The init part shows an error:
“Return from initializer without initializing all stored properties”

How can i solve this? thanks

import SwiftUI
import FirebaseAuth
import Firebase
import FirebaseFirestore

struct ReadQuoteView: View {
    
    @State var displayQuote:String = "Lorem ipsum"
    @State var showSelectCategory = false
    
    @Binding var isLoggedIn: Bool
    
    init() {
        UITextView.appearance().backgroundColor = .clear
    }

    
    
    var body: some View {
        GeometryReader{ geo in
            VStack(){

                Spacer()
                
                //Quote box
                Group{
                    HStack{
                        Spacer()
                        ZStack{
                            Rectangle()
                                .fill(LinearGradient(gradient: Gradient(colors: [Color(UIColor(named: "grad1a")!), Color(UIColor(named: "grad1b")!)]), startPoint: .top, endPoint: .bottomTrailing))
                                .frame(width: geo.size.width * 0.8, height: geo.size.height * 0.6, alignment: .center)
                               
                            ScrollView{
                                TextEditor(text: $displayQuote)
                                    .padding()
                                    .foregroundColor(.white)
                                    .font(.system(size: 20, weight: (.black)))
                                    .frame(width: geo.size.width * 0.8, height: geo.size.height * 0.6, alignment: .center)
                            }
                            .frame(width: geo.size.width * 0.8, height: geo.size.height * 0.6, alignment: .center)
                            
                            VStack{
                                HStack{
                                    Spacer()
                                    Button {
                                        
                                    } label: {
                                        Text("Edit")
                                            .bold()
                                    }
                                    .frame(width: 50, height: 26)
                                    .background(Capsule().stroke(.blue, lineWidth:1))
                                    .padding(15)
                                }
                                Spacer()
                            }
                            .frame(width: geo.size.width * 0.8, height: geo.size.height * 0.6, alignment: .center)
                        }
                        
                        Spacer()
                    }
                }//Group
                
               
                Spacer()
                
                //Forward, Backward, Random
                HStack{
                    Spacer()
                    //ButtonBackward
                    Button {
                        //To Do
                    } label: {
                        Image(systemName: "arrowshape.turn.up.left.circle")
                    }
                    Spacer()
                    //ButtonRandom
                    Button {
                        //To Do
                    } label: {
                        Text("Random")
                    }
                    Spacer()
                    //ButtonForward
                    Button {
                        //To Do
                    } label: {
                        Image(systemName: "arrowshape.turn.up.right.circle")

                    }
                    Spacer()
                }
                
                Spacer()
                
                Group{
                    Button {
                        //To Do
                    } label: {
                        Text("Footnote")
                    }
                    .padding()
                    
                    Button {
                        showSelectCategory = true
                    } label: {
                        Text("Select Showing Categories")
                    }
                    .padding()
                    .sheet(isPresented: $showSelectCategory) { showSelectCategoryView(showSelectCategory: $showSelectCategory)
                    }
                }
                
                Spacer()
            }
            
        }
    }//some View
}//ReadQuoteView

//struct ReadQuoteView_Previews: PreviewProvider {
//    static var previews: some View {
//        ReadQuoteView()
//    }
//}

You need to supply a value for isLoggedIn when you create a ReadQuoteView.

Something like this:

ReadQuoteView(isLoggedIn: $booleanValue)

(with $booleanValue being a Binding to an @State or @Published property from the enclosing View)

In your preview, you can use this:

ReadQuoteView(isLoggedIn: .constant(true)) //or .constant(false)

oh, my bad, it isn’t the preview issue, i know that will be a issue
but even i quote it out, the “Return from initializer without initializing all stored properties” for init part still there

Did you fix the part I told you to fix?

yes, same error

Change your init to this:

    init(isLoggedIn: Binding<Bool>) {
        self._isLoggedIn = isLoggedIn
        UITextView.appearance().backgroundColor = .clear
    }

And make sure to pass a Binding<Bool> when you create a ReadQuoteView.

1 Like