Search code examples
swiftswiftuiwatchkitwatchos

"Type '[view]' cannot conform to 'View'" error when using NavigationLink()


I have a simple Apple Watch app that I'm building with SwiftUI. I'm trying to add a button to go from my ContentView to my SettingsView using NavigationLink

struct ContentView: View {
    
    @EnvironmentObject var settings: SettingsObject
    @EnvironmentObject var chilly: ChillyObject
    
    var body: some View {
        ZStack{
            VStack{

                Text(chilly.message)
                    .foregroundColor(chilly.textColor)
                    .font(.largeTitle)
                    .fontWeight(.heavy)
                    .multilineTextAlignment(.center).fixedSize(horizontal: false, vertical: true)
                    .padding(.top, 9.0)
                            
                Text(chilly.emoji)
                    .font(.largeTitle).foregroundColor(Color.black)
                    .multilineTextAlignment(.center)
                    .padding(.bottom, -20.0)
                
                NavigationLink(destination: SettingsView) {
                    Text("⚙️ Settings")
                        .font(.body)
                        .fontWeight(.semibold)
                }
                .frame(width: 120.0)

            }
        }
    }
}
struct SettingsView: View {
    
    @EnvironmentObject var settings: SettingsObject
            
    var body: some View {
        ZStack {
            VStack {
                Text("Threshold Temp: \(Int(settings.thresholdTemperature))° \(settings.thresholdUnits)")
                    .fontWeight(.light)
                
                Slider(value: $settings.thresholdTemperature, in: 30...90, step: 1)
                    .padding([.leading, .bottom, .trailing])
                
            }
        }
    }
}

I'm getting this error: Type 'SettingsView.Type' cannot conform to 'View'; only struct/enum/class types can conform to protocols on this line: NavigationLink(destination: SettingsView) { in my ContentView.

I think it was introduced when I followed a tutorial and started trying to use the @EnvironmentObject wrapper instead of the @ObservedObject wrapper, but I honestly can't be sure. Any insight would be great. Thanks!


Solution

  • You're passing the type SettingsView for destination parameter, you should be passing an instance instead. Modify this:

    NavigationLink(destination: SettingsView)
    

    To:

    NavigationLink(destination: SettingsView())