Getting: Type 'Service_ValetApp' does not conform to protocol 'App' In Xcode 12.5

623 Views Asked by At

I get a Type 'Service_ValetApp' does not conform to protocol 'App' and I get a fix from the compiler: Do you want to add protocol stubs? Even though I have an init() already in the file. This looks like a bug to me. If anyone has seen this before I would appreciate any and all insights.

import SwiftUI

@main
struct Service_ValetApp: App {
    
    
    @Binding var isInitializing: Bool
    
    init(isInitializing: Binding<Bool>) {
        
        
        self._isInitializing = isInitializing
        
    }
    
   
 
    
   
    var body: some Scene {
        WindowGroup {
            
            MotherView(isInitializing: self.$isInitializing).environmentObject(ViewRouter())
            
          
            
            
        }
    }
}
1

There are 1 best solutions below

1
On BEST ANSWER

Type type App needs to have an initializer that takes zero arguments:

init() {
  //content here
}

You have a argument in your initializer:

init(isInitializing: Binding<Bool>) {

The system is calling init and wouldn't know what to pass for isInitializing.

Secondly, you have a @Binding in your App -- @Binding is used with child views, but this is the top-most parent app component.

Perhaps you meant to use @State with a default value instead:

@main struct Service_ValetApp: App {
    @State var isInitializing : Bool = true
    
    var body: some Scene {
        WindowGroup {
            MotherView(isInitializing: self.$isInitializing)
                .environmentObject(ViewRouter())
        }
    }
}